Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Merged
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
5 changes: 5 additions & 0 deletions .changeset/kind-avocados-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

- Fixed `onFocus` and `onBlur` events of Select component
32 changes: 19 additions & 13 deletions polaris-react/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export interface SelectProps {
/** Callback when selection is changed */
onChange?(selected: string, id: string): void;
/** Callback when select is focused */
onFocus?(): void;
onFocus?(event?: React.FocusEvent<HTMLSelectElement>): void;
/** Callback when focus is removed */
onBlur?(): void;
onBlur?(event?: React.FocusEvent<HTMLSelectElement>): void;
/** Visual required indicator, add an asterisk to label */
requiredIndicator?: boolean;
/** Indicates the tone of the select */
Expand Down Expand Up @@ -114,9 +114,21 @@ export function Select({
disabled && styles.disabled,
);

const handleFocus = useCallback(() => {
toggleFocused();
}, [toggleFocused]);
const handleFocus = useCallback(
(event: React.FocusEvent<HTMLSelectElement>) => {
toggleFocused();
onFocus?.(event);
},
[onFocus, toggleFocused],
);

const handleBlur = useCallback(
(event: React.FocusEvent<HTMLSelectElement>) => {
toggleFocused();
onBlur?.(event);
},
[onBlur, toggleFocused],
);

const handleChange = onChange
? (event: React.ChangeEvent<HTMLSelectElement>) =>
Expand Down Expand Up @@ -196,14 +208,8 @@ export function Select({
value={value}
className={styles.Input}
disabled={disabled}
onFocus={() => {
handleFocus();
onFocus?.();
}}
onBlur={() => {
toggleFocused();
onBlur?.();
}}
onFocus={handleFocus}
onBlur={handleBlur}
onChange={handleChange}
aria-invalid={Boolean(error)}
aria-describedby={
Expand Down