Skip to content

Commit

Permalink
[feat] add autoFocus prop in TypeHead
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta committed Sep 11, 2024
1 parent 7b512cf commit 7659658
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/src/common/item-selector/typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ interface TypeaheadProps {
inputIcon: ElementType;
className?: string;
selectedItems?: any[] | null;
autoFocus: boolean;
// deprecated
maxVisible?: number;
}
Expand Down Expand Up @@ -199,7 +200,8 @@ class Typeahead extends Component<TypeaheadProps, TypeaheadState> {
customListHeaderComponent: null,
showOptionsWhenEmpty: true,
searchable: true,
resultsTruncatedMessage: null
resultsTruncatedMessage: null,
autoFocus: true
};

static getDerivedStateFromProps(props, state) {
Expand Down Expand Up @@ -240,10 +242,12 @@ class Typeahead extends Component<TypeaheadProps, TypeaheadState> {

componentDidMount() {
// call focus on entry or div to trigger key events listener
if (this.entry.current) {
this.entry.current.focus();
} else {
this.root.current?.focus();
if (this.props.autoFocus) {
if (this.entry.current) {
this.entry.current.focus();
} else {
this.root.current?.focus();
}
}
}

Expand Down

0 comments on commit 7659658

Please sign in to comment.