Skip to content

Commit

Permalink
fix: trigger validation when leaving multi text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip committed Nov 1, 2023
1 parent 5c5efcc commit be3462e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@ const MultiSelectFieldComponentPlain = (props: Props) => {
onSelect(multiSelectSelected.join(MULTI_TEXT_SEPARATOR));
};

const handleBlur = () => {
onBlur(selected ? selected.join(MULTI_TEXT_SEPARATOR) : null);
};

return (
<MultiSelectFieldUI
dataTest="multi-select-field"
onChange={onHandleChange}
onFocus={onFocus}
onBlur={onBlur}
onKeyDown={onFocus}
selected={selected}
filterable
filterPlaceholder={translations.filterPlaceholder}
noMatchText={translations.noMatchText}
>
{options.map(option => (
<MultiSelectOption key={option.id} label={option.label} value={option.value} />
))}
</MultiSelectFieldUI>
<div onBlur={handleBlur}>
<MultiSelectFieldUI
dataTest="multi-select-field"
onChange={onHandleChange}
onFocus={onFocus}
onKeyDown={onFocus}
selected={selected}
filterable
filterPlaceholder={translations.filterPlaceholder}
noMatchText={translations.noMatchText}
>
{options.map(option => (
<MultiSelectOption key={option.id} label={option.label} value={option.value} />
))}
</MultiSelectFieldUI>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type MultiSelectOptionConfig = {
export type Props = {
onSelect: (value?: string) => void,
onFocus: () => void,
onBlur: () => void,
onBlur: (value: ?string) => void,
options: Array<MultiSelectOptionConfig>,
value?: string,
translations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ type Props = {
onSetFocus: () => void,
onRemoveFocus: () => void,
inFocus: boolean,
onBlur?: ?(event: SyntheticEvent<HTMLInputElement>) => void,
onBlur?: (value: ?string) => void,
onFocus: () => void,
classes: {
inputWrapperFocused: string,
inputWrapperUnfocused: string,
}
};

export const withFocusHandler = () => (InnerCompnent: React.ComponentType<any>) =>
export const withFocusHandler = () => (InnerComponent: React.ComponentType<any>) =>
class FocusHandlerHOC extends React.Component<Props> {
handleRemoveFocus = () => {
handleRemoveFocus = (value: string) => {
this.props.onRemoveFocus();
this.props.onBlur && this.props.onBlur(value);
}

handleFocus = () => {
Expand All @@ -40,7 +41,7 @@ export const withFocusHandler = () => (InnerCompnent: React.ComponentType<any>)
className={classNames(defaultClasses.inputWrapper, inputWrapper)}
>
{/* $FlowFixMe[cannot-spread-inexact] automated comment */}
<InnerCompnent
<InnerComponent
onFocus={this.handleFocus}
onBlur={this.handleRemoveFocus}
onSelect={this.handleSelect}
Expand Down

0 comments on commit be3462e

Please sign in to comment.