Skip to content

Commit 2d9db12

Browse files
authored
feat: Support associating components with external forms (#8411)
1 parent ef0ddfe commit 2d9db12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+286
-80
lines changed

packages/@react-aria/button/src/useButton.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ export function useButton(props: AriaButtonOptions<ElementType>, ref: RefObject<
6767
if (elementType === 'button') {
6868
additionalProps = {
6969
type,
70-
disabled: isDisabled
70+
disabled: isDisabled,
71+
form: props.form,
72+
formAction: props.formAction,
73+
formEncType: props.formEncType,
74+
formMethod: props.formMethod,
75+
formNoValidate: props.formNoValidate,
76+
formTarget: props.formTarget,
77+
name: props.name,
78+
value: props.value
7179
};
7280
} else {
7381
additionalProps = {

packages/@react-aria/checkbox/src/useCheckboxGroup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface CheckboxGroupAria extends ValidationResult {
3636
* @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.
3737
*/
3838
export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {
39-
let {isDisabled, name, validationBehavior = 'aria'} = props;
39+
let {isDisabled, name, form, validationBehavior = 'aria'} = props;
4040
let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
4141

4242
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
@@ -50,6 +50,7 @@ export function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxG
5050

5151
checkboxGroupData.set(state, {
5252
name,
53+
form,
5354
descriptionId: descriptionProps.id,
5455
errorMessageId: errorMessageProps.id,
5556
validationBehavior

packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
4444
}
4545
});
4646

47-
let {name, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;
47+
let {name, form, descriptionId, errorMessageId, validationBehavior} = checkboxGroupData.get(state)!;
4848
validationBehavior = props.validationBehavior ?? validationBehavior;
4949

5050
// Local validation for this checkbox.
@@ -73,6 +73,7 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
7373
isReadOnly: props.isReadOnly || state.isReadOnly,
7474
isDisabled: props.isDisabled || state.isDisabled,
7575
name: props.name || name,
76+
form: props.form || form,
7677
isRequired: props.isRequired ?? state.isRequired,
7778
validationBehavior,
7879
[privateValidationStateProp]: {

packages/@react-aria/checkbox/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {CheckboxGroupState} from '@react-stately/checkbox';
1414

1515
interface CheckboxGroupData {
1616
name?: string,
17+
form?: string,
1718
descriptionId?: string,
1819
errorMessageId?: string,
1920
validationBehavior: 'aria' | 'native'

packages/@react-aria/color/src/useColorArea.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
5454
containerRef,
5555
'aria-label': ariaLabel,
5656
xName,
57-
yName
57+
yName,
58+
form
5859
} = props;
5960
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/color');
6061

@@ -426,6 +427,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
426427
disabled: isDisabled,
427428
value: state.value.getChannelValue(xChannel),
428429
name: xName,
430+
form,
429431
tabIndex: (isMobile || !focusedInput || focusedInput === 'x' ? undefined : -1),
430432
/*
431433
So that only a single "2d slider" control shows up when listing form elements for screen readers,
@@ -451,6 +453,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
451453
disabled: isDisabled,
452454
value: state.value.getChannelValue(yChannel),
453455
name: yName,
456+
form,
454457
tabIndex: (isMobile || focusedInput === 'y' ? undefined : -1),
455458
/*
456459
So that only a single "2d slider" control shows up when listing form elements for screen readers,

packages/@react-aria/color/src/useColorSlider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ColorSliderAria {
4444
* Color sliders allow users to adjust an individual channel of a color value.
4545
*/
4646
export function useColorSlider(props: AriaColorSliderOptions, state: ColorSliderState): ColorSliderAria {
47-
let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel, name} = props;
47+
let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel, name, form} = props;
4848

4949
let {locale, direction} = useLocale();
5050

@@ -60,6 +60,7 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
6060
orientation,
6161
isDisabled: props.isDisabled,
6262
name,
63+
form,
6364
trackRef,
6465
inputRef
6566
}, state);

packages/@react-aria/color/src/useColorWheel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
4545
innerRadius,
4646
outerRadius,
4747
'aria-label': ariaLabel,
48-
name
48+
name,
49+
form
4950
} = props;
5051

5152
let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
@@ -325,6 +326,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
325326
disabled: isDisabled,
326327
value: `${state.value.getChannelValue('hue')}`,
327328
name,
329+
form,
328330
onChange: (e: ChangeEvent<HTMLInputElement>) => {
329331
state.setHue(parseFloat(e.target.value));
330332
},

packages/@react-aria/datepicker/src/useDateField.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export function useDateField<T extends DateValue>(props: AriaDateFieldOptions<T>
149149
let inputProps: InputHTMLAttributes<HTMLInputElement> = {
150150
type: 'hidden',
151151
name: props.name,
152+
form: props.form,
152153
value: state.value?.toString() || '',
153154
disabled: props.isDisabled
154155
};

packages/@react-aria/datepicker/src/useDatePicker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export function useDatePicker<T extends DateValue>(props: AriaDatePickerProps<T>
150150
// DatePicker owns the validation state for the date field.
151151
[privateValidationStateProp]: state,
152152
autoFocus: props.autoFocus,
153-
name: props.name
153+
name: props.name,
154+
form: props.form
154155
},
155156
descriptionProps,
156157
errorMessageProps,

packages/@react-aria/datepicker/src/useDateRangePicker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePick
187187
onChange: start => state.setDateTime('start', start),
188188
autoFocus: props.autoFocus,
189189
name: props.startName,
190+
form: props.form,
190191
[privateValidationStateProp]: {
191192
realtimeValidation: state.realtimeValidation,
192193
displayValidation: state.displayValidation,
@@ -205,6 +206,7 @@ export function useDateRangePicker<T extends DateValue>(props: AriaDateRangePick
205206
defaultValue: state.defaultValue?.end,
206207
onChange: end => state.setDateTime('end', end),
207208
name: props.endName,
209+
form: props.form,
208210
[privateValidationStateProp]: {
209211
realtimeValidation: state.realtimeValidation,
210212
displayValidation: state.displayValidation,

0 commit comments

Comments
 (0)