Skip to content

Commit b460b14

Browse files
authored
fix(react-checkbox, react-input, react-select, react-spinbutton): merge Field control props in base hooks (#36312)
1 parent f2b97d7 commit b460b14

8 files changed

Lines changed: 50 additions & 20 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: move Field control props to base hooks",
4+
"packageName": "@fluentui/react-checkbox",
5+
"email": "dmytrokirpa@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: move Field control props to base hooks",
4+
"packageName": "@fluentui/react-input",
5+
"email": "dmytrokirpa@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: move Field control props to base hooks",
4+
"packageName": "@fluentui/react-select",
5+
"email": "dmytrokirpa@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: move Field control props to base hooks",
4+
"packageName": "@fluentui/react-spinbutton",
5+
"email": "dmytrokirpa@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-checkbox/library/src/components/Checkbox/useCheckbox.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ import { useFocusWithin } from '@fluentui/react-tabster';
3232
* @param ref - reference to `<input>` element of Checkbox
3333
*/
3434
export const useCheckbox_unstable = (props: CheckboxProps, ref: React.Ref<HTMLInputElement>): CheckboxState => {
35-
// Merge props from surrounding <Field>, if any
36-
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });
37-
3835
const { shape = 'square', size = 'medium', ...checkboxProps } = props;
3936

4037
const state = useCheckboxBase_unstable(checkboxProps, ref);
@@ -88,6 +85,9 @@ export const useCheckboxBase_unstable = (
8885
): CheckboxBaseState => {
8986
'use no memo'; // justified: compiler would optimize useCheckboxBase_unstable — manual opt-out to preserve runtime behavior
9087

88+
// Merge props from surrounding <Field>, if any
89+
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });
90+
9191
const { disabled = false, required, labelPosition = 'after', onChange } = props;
9292

9393
const [checked, setChecked] = useControllableState({

packages/react-components/react-input/library/src/components/Input/useInput.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-co
1616
* @param ref - reference to `<input>` element of Input
1717
*/
1818
export const useInput_unstable = (props: InputProps, ref: React.Ref<HTMLInputElement>): InputState => {
19-
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true, supportsSize: true });
20-
2119
const overrides = useOverrides();
2220

2321
const { size = 'medium', appearance = overrides.inputDefaultAppearance ?? 'outline', ...baseProps } = props;
@@ -50,16 +48,20 @@ export const useInput_unstable = (props: InputProps, ref: React.Ref<HTMLInputEle
5048
* @param ref - User provided ref to be passed to the Input component.
5149
*/
5250
export const useInputBase_unstable = (props: InputBaseProps, ref: React.Ref<HTMLInputElement>): InputBaseState => {
53-
const { onChange } = props;
51+
const fieldControlProps = useFieldControlProps_unstable(props, {
52+
supportsLabelFor: true,
53+
supportsRequired: true,
54+
supportsSize: true,
55+
});
5456

5557
const [value, setValue] = useControllableState({
56-
state: props.value,
57-
defaultState: props.defaultValue,
58+
state: fieldControlProps.value,
59+
defaultState: fieldControlProps.defaultValue,
5860
initialState: '',
5961
});
6062

6163
const nativeProps = getPartitionedNativeProps({
62-
props,
64+
props: fieldControlProps,
6365
primarySlotTagName: 'input',
6466
excludedPropNames: ['onChange', 'value', 'defaultValue'],
6567
});
@@ -71,17 +73,17 @@ export const useInputBase_unstable = (props: InputBaseProps, ref: React.Ref<HTML
7173
contentBefore: 'span',
7274
contentAfter: 'span',
7375
},
74-
input: slot.always(props.input, {
76+
input: slot.always(fieldControlProps.input, {
7577
defaultProps: {
7678
type: 'text',
7779
ref,
7880
...nativeProps.primary,
7981
},
8082
elementType: 'input',
8183
}),
82-
contentAfter: slot.optional(props.contentAfter, { elementType: 'span' }),
83-
contentBefore: slot.optional(props.contentBefore, { elementType: 'span' }),
84-
root: slot.always(props.root, {
84+
contentAfter: slot.optional(fieldControlProps.contentAfter, { elementType: 'span' }),
85+
contentBefore: slot.optional(fieldControlProps.contentBefore, { elementType: 'span' }),
86+
root: slot.always(fieldControlProps.root, {
8587
defaultProps: nativeProps.root,
8688
elementType: 'span',
8789
}),
@@ -90,7 +92,7 @@ export const useInputBase_unstable = (props: InputBaseProps, ref: React.Ref<HTML
9092
state.input.value = value;
9193
state.input.onChange = useEventCallback(ev => {
9294
const newValue = ev.target.value;
93-
onChange?.(ev, { value: newValue });
95+
fieldControlProps.onChange?.(ev, { value: newValue });
9496
setValue(newValue);
9597
});
9698

packages/react-components/react-select/library/src/components/Select/useSelect.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-co
1717
* @param ref - reference to the `<select>` element in Select
1818
*/
1919
export const useSelect_unstable = (props: SelectProps, ref: React.Ref<HTMLSelectElement>): SelectState => {
20-
// Merge props from surrounding <Field>, if any
21-
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true, supportsSize: true });
22-
2320
const overrides = useOverrides();
2421

2522
const { appearance = overrides.inputDefaultAppearance ?? 'outline', size = 'medium', ...baseProps } = props;
@@ -40,6 +37,9 @@ export const useSelect_unstable = (props: SelectProps, ref: React.Ref<HTMLSelect
4037
* @param ref - reference to the `<select>` element in Select
4138
*/
4239
export const useSelectBase_unstable = (props: SelectBaseProps, ref: React.Ref<HTMLSelectElement>): SelectBaseState => {
40+
// Merge props from surrounding <Field>, if any
41+
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });
42+
4343
const { defaultValue, value, select, icon, root, onChange } = props;
4444

4545
const nativeProps = getPartitionedNativeProps({

packages/react-components/react-spinbutton/library/src/components/SpinButton/useSpinButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const useSpinButtonBase_unstable = (
5252
props: SpinButtonBaseProps,
5353
ref: React.Ref<HTMLInputElement>,
5454
): SpinButtonBaseState => {
55+
// Merge props from surrounding <Field>, if any
56+
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });
57+
5558
const nativeProps = getPartitionedNativeProps({
5659
props,
5760
primarySlotTagName: 'input',
@@ -387,9 +390,6 @@ export const useSpinButtonBase_unstable = (
387390
* @param ref - reference to root HTMLElement of SpinButton
388391
*/
389392
export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {
390-
// Merge props from surrounding <Field>, if any
391-
props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });
392-
393393
const overrides = useOverrides();
394394

395395
const { appearance = overrides.inputDefaultAppearance ?? 'outline', size = 'medium', ...baseProps } = props;

0 commit comments

Comments
 (0)