1
0
mirror of synced 2024-11-22 13:06:08 +03:00

fix incorrect dropdown behavior when multi+openOnFocus and selection is made via mouse

This commit is contained in:
Igor Vaynberg 2019-11-06 10:32:02 -08:00
parent 92ca33cd74
commit 6705eafc7f
3 changed files with 55 additions and 32 deletions

View File

@ -297,23 +297,6 @@ export class MultiSelect extends AbstractSelect<Props, State> {
this.selectSearchResult(index); this.selectSearchResult(index);
}; };
public selectActiveResult = () => {
this.selectResult(this.getSelectedSearchResult());
};
public selectResult = (result: any) => {
const { values, onChange } = this.props;
const next = values.slice();
next.push(result);
this.close();
const label = this.getItemLabel(result);
announce.politely(this.dictionary.valueAdded(label));
onChange(next);
};
public toggleValue = (index: number) => { public toggleValue = (index: number) => {
const { const {
values: { selected } values: { selected }
@ -358,8 +341,7 @@ export class MultiSelect extends AbstractSelect<Props, State> {
if (this.hasSearchResults) { if (this.hasSearchResults) {
switch (event.key) { switch (event.key) {
case Key.Enter: case Key.Enter:
this.selectActiveResult(); this.onActiveResultSelectedViaKeypress(event);
event.preventDefault();
break; break;
case Key.Escape: case Key.Escape:
if (open) { if (open) {
@ -412,12 +394,15 @@ export class MultiSelect extends AbstractSelect<Props, State> {
} }
} }
public close = () => { public close = (callback?: () => void) => {
this.updateState({ this.updateState(
{
open: false, open: false,
results: { results: undefined }, results: { results: undefined },
search: '' search: ''
}); },
callback
);
}; };
public onValuesBlur = (event: Event) => { public onValuesBlur = (event: Event) => {
@ -487,9 +472,47 @@ export class MultiSelect extends AbstractSelect<Props, State> {
}; };
public onResultClicked = (result: any, event: MouseEvent) => { public onResultClicked = (result: any, event: MouseEvent) => {
this.selectResult(result); const { openOnFocus } = this.props;
const values = this.selectResult(result);
const focusSearchLater = () => {
window.setTimeout(() => {
this.searchRef.current!.focus(); this.searchRef.current!.focus();
}, 0);
};
if (openOnFocus) {
this.search('', values, {}, focusSearchLater);
} else {
this.close(focusSearchLater);
}
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
}; };
public onActiveResultSelectedViaKeypress = (event: KeyboardEvent) => {
const { openOnFocus } = this.props;
const result = this.getSelectedSearchResult();
const values = this.selectResult(result);
if (openOnFocus) {
this.search('', values, { open: true });
} else {
this.close();
}
event.preventDefault();
};
public selectResult = (result: any) => {
const { values, onChange } = this.props;
const next = values.slice();
next.push(result);
const label = this.getItemLabel(result);
announce.politely(this.dictionary.valueAdded(label));
onChange(next);
return next;
};
} }

8
dist/select25.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long