Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Select): autoFocus property #1990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ LANDING_BLOCK-->
| className | Control className | `string` | |
| defaultValue | Default values that represent selected options in case of using uncontrolled state | `string[]` | |
| disabled | Indicates that the user cannot interact with the control | `boolean` | `false` |
| autoFocus | Sets focus on | `boolean` | `false` |
| [filterable](#filtering-options) | Indicates that select popup have filter section | `boolean` | `false` |
| filterOption | Used to compare option with filter | `function` | |
| filterPlaceholder | Default filter input placeholder text | `string` | |
Expand Down
5 changes: 5 additions & 0 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
hasCounter,
renderCounter,
title,
autoFocus = false,
} = props;
const mobile = useMobile();
const [filter, setFilter] = useControlledState(propsFilter, '', onFilterChange);
Expand All @@ -122,6 +123,10 @@ export const Select = React.forwardRef<HTMLButtonElement, SelectProps>(function
disabled,
});

React.useEffect(() => {
if (autoFocus) controlRef.current?.focus();
}, [autoFocus]);

React.useEffect(() => {
if (!open && filterable && mobile) {
// FIXME: add handlers to Sheet like in https://github.com/gravity-ui/uikit/issues/1354
Expand Down
1 change: 1 addition & 0 deletions src/components/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export type SelectProps<T = any> = QAProps &
name?: string;
form?: string;
disabled?: boolean;
autoFocus?: boolean;
};

export type SelectOption<T = any> = QAProps &
Expand Down
Loading