Skip to content
Closed
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
10 changes: 7 additions & 3 deletions packages/@react-aria/select/src/HiddenSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export interface AriaHiddenSelectProps {
name?: string,

/** Sets the disabled state of the select and input. */
isDisabled?: boolean
isDisabled?: boolean,

/** Whether user input is required on the input before form submission. */
isRequired?: boolean
}

export interface HiddenSelectProps<T> extends AriaHiddenSelectProps {
Expand All @@ -52,7 +55,7 @@ export interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {
* navigation, and native HTML form submission.
*/
export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: SelectState<T>, triggerRef: RefObject<FocusableElement>) {
let {autoComplete, name, isDisabled} = props;
let {autoComplete, name, isDisabled, isRequired} = props;
let modality = useInteractionModality();
let {visuallyHiddenProps} = useVisuallyHidden();

Expand Down Expand Up @@ -87,7 +90,8 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
style: {fontSize: 16},
onFocus: () => triggerRef.current.focus(),
disabled: isDisabled
disabled: isDisabled,
required: isRequired
},
selectProps: {
tabIndex: -1,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-aria-components/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ function Select<T extends object>(props: SelectProps<T>, ref: ForwardedRef<HTMLD
triggerRef={buttonRef}
label={label}
name={props.name}
isDisabled={props.isDisabled} />
isDisabled={props.isDisabled}
isRequired={props.isRequired} />
</Provider>
</>
);
Expand Down
9 changes: 9 additions & 0 deletions packages/react-aria-components/test/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,13 @@ describe('Select', () => {

expect(document.activeElement).toBe(document.body);
});

it('should send required prop to the hidden field', () => {
let {container} = render(
<TestSelect isRequired />
);

let input = container.querySelector('input');
expect(input).toHaveAttribute('required');
});
});