fix incorrect dropdown behavior when multi+openOnFocus and selection is made via mouse
This commit is contained in:
parent
92ca33cd74
commit
6705eafc7f
@ -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,
|
{
|
||||||
results: { results: undefined },
|
open: false,
|
||||||
search: ''
|
results: { results: undefined },
|
||||||
});
|
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;
|
||||||
this.searchRef.current!.focus();
|
const values = this.selectResult(result);
|
||||||
|
|
||||||
|
const focusSearchLater = () => {
|
||||||
|
window.setTimeout(() => {
|
||||||
|
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
8
dist/select25.js
vendored
File diff suppressed because one or more lines are too long
2
dist/select25.js.map
vendored
2
dist/select25.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user