Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/pill-selector-dropdown/PillSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Props = {
suggestedPillsData?: Array<Object>,
suggestedPillsFilter?: SuggestedPillsFilter,
suggestedPillsTitle?: string,
/** A CSS class for the tooltip's target wrapper element */
tooltipWrapperClassName?: string,
validator: (option: Option | OptionValue) => boolean,
};

Expand Down Expand Up @@ -211,6 +213,7 @@ class PillSelectorBase extends React.Component<Props, State> {
suggestedPillsData,
suggestedPillsFilter,
suggestedPillsTitle,
tooltipWrapperClassName,
validator,
...rest
} = this.props;
Expand All @@ -231,7 +234,13 @@ class PillSelectorBase extends React.Component<Props, State> {
};

return (
<Tooltip isShown={hasError} text={error || ''} position={errorTooltipPosition} theme="error">
<Tooltip
isShown={hasError}
position={errorTooltipPosition}
targetWrapperClassName={tooltipWrapperClassName}
text={error || ''}
theme="error"
>
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<span
className={classes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type Props = {
suggestedPillsFilter?: SuggestedPillsFilter,
/** String describes the suggested pills */
suggestedPillsTitle?: string,
/** A CSS class for the tooltip's target wrapper element */
tooltipWrapperClassName?: string,
/** Validate the given input value, and update `error` prop if necessary */
validateForError?: Function,
/** Called to check if pill item data is valid. The `item` is passed in. */
Expand Down Expand Up @@ -258,6 +260,7 @@ class PillSelectorDropdown extends React.Component<Props, State> {
suggestedPillsFilter,
suggestedPillsTitle,
shouldSetActiveItemOnOpen,
tooltipWrapperClassName,
validator,
} = this.props;

Expand Down Expand Up @@ -295,6 +298,7 @@ class PillSelectorDropdown extends React.Component<Props, State> {
suggestedPillsData={suggestedPillsData}
suggestedPillsFilter={suggestedPillsFilter}
suggestedPillsTitle={suggestedPillsTitle}
tooltipWrapperClassName={tooltipWrapperClassName}
validator={validator}
value={this.state.inputValue}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ describe('components/pill-selector-dropdown/PillSelector', () => {
expect(wrapper.find('.show-error').length).toBe(0);
});

test('should pass tooltipWrapperClassName to Tooltip as targetWrapperClassName when provided', () => {
const tooltipWrapperClassName = 'custom-tooltip-wrapper';
const wrapper = shallow(
<PillSelector
error="error"
onInput={onInputStub}
onRemove={onRemoveStub}
tooltipWrapperClassName={tooltipWrapperClassName}
/>,
);

expect(wrapper.find('Tooltip').prop('targetWrapperClassName')).toBe(tooltipWrapperClassName);
});

test('should render pills when there are selected options using legacy text attribute', () => {
const options = [
{ text: 'test', value: 'test' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe('components/pill-selector-dropdown/PillSelectorDropdown', () => {
expect(pillSelector.dive().instance().props.value).toEqual('value');
});

test('should pass tooltipWrapperClassName to PillSelector when provided', () => {
const tooltipWrapperClassName = 'custom-tooltip-wrapper';
const wrapper = getWrapper({ tooltipWrapperClassName });
const selectorElement = wrapper.find('SelectorDropdown').prop('selector');

expect(selectorElement.props.tooltipWrapperClassName).toBe(tooltipWrapperClassName);
});

test('should render disabled pill selector', () => {
const wrapper = getWrapper({ disabled: true });

Expand Down
4 changes: 4 additions & 0 deletions src/components/text-area/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Props = {
textareaRef?: Function, // @TODO: eventually rename to innerRef for consistancy across all form elements
/** A CSS class for the tooltip's tether element component */
tooltipTetherClassName?: string,
/** A CSS class for the tooltip's target wrapper element */
tooltipWrapperClassName?: string,
};

const TextArea = ({
Expand All @@ -42,6 +44,7 @@ const TextArea = ({
label,
textareaRef,
tooltipTetherClassName,
tooltipWrapperClassName,
...rest
}: Props) => {
const hasError = !!error;
Expand Down Expand Up @@ -70,6 +73,7 @@ const TextArea = ({
<Tooltip
isShown={hasError}
position={errorTooltipPosition || 'bottom-left'}
targetWrapperClassName={tooltipWrapperClassName}
tetherElementClassName={tooltipTetherClassName}
text={error || ''}
theme="error"
Expand Down
9 changes: 9 additions & 0 deletions src/components/text-area/__tests__/TextArea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ describe('components/text-area/TextArea', () => {
wrapper.unmount();
});

test('should pass tooltipWrapperClassName to Tooltip as targetWrapperClassName when provided', () => {
const tooltipWrapperClassName = 'custom-tooltip-wrapper';
const wrapper = shallow(
<TextArea error="error" label="label" tooltipWrapperClassName={tooltipWrapperClassName} />,
);

expect(wrapper.find('Tooltip').prop('targetWrapperClassName')).toBe(tooltipWrapperClassName);
});

test('should not show optional text when hideOptionalLabel is true', () => {
const wrapper = shallow(<TextArea label="label" hideOptionalLabel />);
expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`components/text-area/TextArea should not show optional text when hideOp
theme="error"
>
<textarea
aria-errormessage="errorMessage22"
aria-errormessage="errorMessage24"
aria-invalid={false}
style={
{
Expand All @@ -29,7 +29,7 @@ exports[`components/text-area/TextArea should not show optional text when hideOp
</Tooltip>
<span
className="accessibility-hidden"
id="errorMessage22"
id="errorMessage24"
role="alert"
/>
</Label>
Expand All @@ -46,7 +46,7 @@ exports[`components/text-area/TextArea should render text area with description
>
<div
className="text-area-description"
id="description27"
id="description29"
>
some description
</div>
Expand All @@ -60,8 +60,8 @@ exports[`components/text-area/TextArea should render text area with description
theme="error"
>
<textarea
aria-describedby="description27"
aria-errormessage="errorMessage26"
aria-describedby="description29"
aria-errormessage="errorMessage28"
aria-invalid={false}
style={
{
Expand All @@ -72,7 +72,7 @@ exports[`components/text-area/TextArea should render text area with description
</Tooltip>
<span
className="accessibility-hidden"
id="errorMessage26"
id="errorMessage28"
role="alert"
/>
</Label>
Expand All @@ -97,7 +97,7 @@ exports[`components/text-area/TextArea should show optional text when hideOption
theme="error"
>
<textarea
aria-errormessage="errorMessage24"
aria-errormessage="errorMessage26"
aria-invalid={false}
style={
{
Expand All @@ -108,7 +108,7 @@ exports[`components/text-area/TextArea should show optional text when hideOption
</Tooltip>
<span
className="accessibility-hidden"
id="errorMessage24"
id="errorMessage26"
role="alert"
/>
</Label>
Expand Down
2 changes: 2 additions & 0 deletions src/features/shared-link-modal/EmailSharedLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class EmailSharedLink extends Component {
placeholder={formatMessage(commonMessages.pillSelectorPlaceholder)}
selectedOptions={selectedOptions}
selectorOptions={selectorOptions}
tooltipWrapperClassName="bdl-EmailSharedLink-tooltipWrapper"
validateForError={this.validateForError}
validator={this.validator}
>
Expand All @@ -199,6 +200,7 @@ class EmailSharedLink extends Component {
label={<FormattedMessage {...messages.messageTitle} />}
onChange={this.handleMessageChange}
rows={3}
tooltipWrapperClassName="bdl-EmailSharedLink-tooltipWrapper"
value={emailMessage}
/>
{isExpanded && (
Expand Down
4 changes: 4 additions & 0 deletions src/features/shared-link-modal/EmailSharedLink.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
transition: height 0.2s;
}

.bdl-EmailSharedLink-tooltipWrapper {
width: 100%;
}

.bdl-PillSelector,
textarea {
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,12 @@ describe('features/shared-link-modal/EmailSharedLink', () => {
expect(pillSelector.length).toBe(1);
expect(pillSelector.find('ContactDatalistItem').length).toBe(11);
expect(pillSelector.prop('inputProps')['data-resin-thing']).toEqual('hey');
expect(pillSelector.prop('tooltipWrapperClassName')).toBe('bdl-EmailSharedLink-tooltipWrapper');
pillSelector.prop('inputProps').onFocus(); // should call props.onExpand

const textArea = wrapper.find('TextArea');
expect(textArea.length).toBe(1);
expect(textArea.prop('tooltipWrapperClassName')).toBe('bdl-EmailSharedLink-tooltipWrapper');
});

test('should add is-expanded class to form and show buttons when props.isExpanded is true', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/features/unified-share-modal/ContactsField.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Props = {
getPillClassName?: (option: SelectOptionProp) => string,
intl: any,
label: React.Node,
/** A CSS class for the tooltip's target wrapper element */
tooltipWrapperClassName?: string,
onContactAdd: Function,
onContactRemove: Function,
onInput?: Function,
Expand Down Expand Up @@ -175,6 +177,7 @@ class ContactsField extends React.Component<Props, State> {
onPillCreate,
selectedContacts,
showContactAvatars,
tooltipWrapperClassName,
validateForError,
validator,
} = this.props;
Expand Down Expand Up @@ -213,6 +216,7 @@ class ContactsField extends React.Component<Props, State> {
showAvatars
showRoundedPills
selectorOptions={contacts}
tooltipWrapperClassName={tooltipWrapperClassName}
validateForError={validateForError}
validator={validator}
>
Expand Down
19 changes: 8 additions & 11 deletions src/features/unified-share-modal/EmailForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ class EmailForm extends React.Component<Props, State> {
const { isRestrictionJustificationEnabled } = this.props;
const { isRestrictionJustificationEnabled: prevIsRestrictionJustificationEnabled } = prevProps;
const { contactsFieldError, contactsRestrictionError } = this.state;
const {
contactsFieldError: prevContactsFieldError,
contactsRestrictionError: prevContactsRestrictionError,
} = prevState;
const { contactsFieldError: prevContactsFieldError, contactsRestrictionError: prevContactsRestrictionError } =
prevState;

// Only display one type of error at a time and give preference
// to the one triggered most recently
Expand Down Expand Up @@ -189,13 +187,8 @@ class EmailForm extends React.Component<Props, State> {
validateContactsRestrictions = () => {
let contactsRestrictionError = '';
const { selectedJustificationReason } = this.state;
const {
intl,
isRestrictionJustificationEnabled,
selectedContacts,
restrictedEmails,
restrictedGroups,
} = this.props;
const { intl, isRestrictionJustificationEnabled, selectedContacts, restrictedEmails, restrictedGroups } =
this.props;

const hasRestrictedCollabs = hasRestrictedContacts(selectedContacts, restrictedEmails, restrictedGroups);
const isMissingRequiredJustification = isRestrictionJustificationEnabled && !selectedJustificationReason;
Expand Down Expand Up @@ -395,13 +388,15 @@ class EmailForm extends React.Component<Props, State> {
isShown: showEnterEmailsCallout,
position: 'middle-right',
showCloseButton: true,
targetWrapperClassName: 'bdl-UnifiedShareModal-tooltipWrapper',
text: <FormattedMessage {...messages.enterEmailAddressesCalloutText} />,
theme: 'callout',
};

const recommendedSharingTooltipProps = {
isShown: !!recommendedSharingTooltipCalloutName,
position: 'middle-left',
targetWrapperClassName: 'bdl-UnifiedShareModal-tooltipWrapper',
text: (
<FormattedMessage
{...messages.recommendedSharingTooltipCalloutText}
Expand Down Expand Up @@ -432,6 +427,7 @@ class EmailForm extends React.Component<Props, State> {
onPillCreate={onPillCreate}
selectedContacts={selectedContacts}
suggestedCollaborators={suggestedCollaborators}
tooltipWrapperClassName="bdl-UnifiedShareModal-tooltipWrapper"
validateForError={this.validateContactField}
validator={this.isValidContactPill}
showContactAvatars
Expand Down Expand Up @@ -490,6 +486,7 @@ class EmailForm extends React.Component<Props, State> {
onChange={this.handleMessageChange}
placeholder={intl.formatMessage(commonMessages.messageSelectorPlaceholder)}
rows={3}
tooltipWrapperClassName="bdl-UnifiedShareModal-tooltipWrapper"
value={message}
{...messageProps}
/>
Expand Down
4 changes: 4 additions & 0 deletions src/features/unified-share-modal/UnifiedShareModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
display: block;
}

.bdl-UnifiedShareModal-tooltipWrapper {
width: 100%;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why tooltip wrapper impacts the input ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the latest Tooltip change added display: inline-block; to tooltip wrapper


.usm-ftux-toggle-tooltip-target {
flex: 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('features/unified-share-modal/ContactsField', () => {

const suggestions = {
// expectedContacts[1]
'23456': {
23456: {
id: '23456',
userScore: 0.5,
email: 'y@example.com',
Expand All @@ -76,7 +76,7 @@ describe('features/unified-share-modal/ContactsField', () => {
isExternalUser: false,
},
// expectedContacts[2]
'34567': {
34567: {
id: '34567',
userScore: 0.1,
email: 'z@example.com',
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('features/unified-share-modal/ContactsField', () => {
expect(addSuggestedContactsMock).not.toHaveBeenCalled();

wrapper.setProps({
suggestedCollaborators: { '12345': { id: 12345 }, '23456': { id: 23456 } },
suggestedCollaborators: { 12345: { id: 12345 }, 23456: { id: 23456 } },
});

wrapper.instance().filterContacts(contactsFromServer);
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('features/unified-share-modal/ContactsField', () => {
test('should pass overlayTitle when there are suggested collabs', async () => {
const wrapper = getWrapper({
getContacts,
suggestedCollaborators: { '12': { id: 12, userScore: 1 } },
suggestedCollaborators: { 12: { id: 12, userScore: 1 } },
});

wrapper.setState({ pillSelectorInputValue: 'a' });
Expand All @@ -388,13 +388,20 @@ describe('features/unified-share-modal/ContactsField', () => {
test('should render divider at the correct index when there are suggested collabs', async () => {
const wrapper = getWrapper({
getContacts,
suggestedCollaborators: { '12': { id: 12, userScore: 1 } },
suggestedCollaborators: { 12: { id: 12, userScore: 1 } },
});

wrapper.setState({ pillSelectorInputValue: 'a' });
await wrapper.instance().getContactsPromise('a');

expect(wrapper.find('PillSelectorDropdown').props().dividerIndex).toBe(1);
});

test('should pass tooltipWrapperClassName to PillSelectorDropdown when provided', () => {
const tooltipWrapperClassName = 'bdl-UnifiedShareModal-tooltipWrapper';
const wrapper = getWrapper({ tooltipWrapperClassName });

expect(wrapper.find('PillSelectorDropdown').prop('tooltipWrapperClassName')).toBe(tooltipWrapperClassName);
});
});
});
Loading