Skip to content

Commit 50b2ffb

Browse files
tomsontomLFDanLu
andauthored
provide autofocus property (#1330)
Co-authored-by: Daniel Lu <dlu@livefyre.com>
1 parent 2cacc4f commit 50b2ffb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

packages/@react-spectrum/picker/src/Picker.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function Picker<T extends object>(props: SpectrumPickerProps<T>, ref: DOMRef<HTM
5555
isRequired,
5656
necessityIndicator,
5757
menuWidth,
58-
name
58+
name,
59+
autoFocus
5960
} = props;
6061

6162
let {styleProps} = useStyleProps(props);
@@ -212,6 +213,7 @@ function Picker<T extends object>(props: SpectrumPickerProps<T>, ref: DOMRef<HTM
212213
isQuiet={isQuiet}
213214
isDisabled={isDisabled}
214215
validationState={validationState}
216+
autoFocus={autoFocus}
215217
UNSAFE_className={classNames(styles, 'spectrum-Dropdown-trigger', {'is-hovered': isHovered})}>
216218
<SlotProvider
217219
slots={{

packages/@react-spectrum/picker/stories/Picker.stories.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,14 @@ storiesOf('Picker', module)
500500
<AsyncLoadingExample />
501501
)
502502
)
503-
.add('resize', () => <ResizePicker />);
503+
.add('resize', () => <ResizePicker />)
504+
.add('autofocus', () => (
505+
<Picker label="Test" autoFocus>
506+
<Item key="One">One</Item>
507+
<Item key="Two">Two</Item>
508+
<Item key="Three">Three</Item>
509+
</Picker>
510+
));
504511

505512
function AsyncLoadingExample() {
506513
interface Pokemon {

packages/@react-types/select/src/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ export interface SpectrumPickerProps<T> extends AriaSelectProps<T>, SpectrumLabe
5959
/**
6060
* The name of the Picker input, used when submitting an HTML form.
6161
*/
62-
name?: string
62+
name?: string,
63+
/** Whether the element should receive focus on render. */
64+
autoFocus?: boolean
6365
}

0 commit comments

Comments
 (0)