Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[feat] add autoFocus prop in TypeHead (#2646)

Igor Dykhta6f45f1f088e5
diff --git a/src/components/src/common/item-selector/typeahead.tsx b/src/components/src/common/item-selector/typeahead.tsx
index b1e2212da..9192f1bc0 100644
--- a/src/components/src/common/item-selector/typeahead.tsx
+++ b/src/components/src/common/item-selector/typeahead.tsx
@@ -147,6 +147,7 @@ interface TypeaheadProps {
inputIcon: ElementType;
className?: string;
selectedItems?: any[] | null;
+ autoFocus: boolean;
// deprecated
maxVisible?: number;
}
@@ -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) {
@@ -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();
+ }
}
}