Skip to content

Commit 52611a5

Browse files
🐞 fix #11842 radio buttons not disabled when multiple share a name (#11873)
* feat: allow `iterateFieldsByAction` to iterate over multiple refs * fix: `_disableForm` only disables one input when inputs share a name * test: add unit tests for action iteration over multiple refs * refactor: invert `abortEarly` param's logic to respect semantic meaning * refactor: move ref iteration logic to if block * chore: fix lint errors * test: rename tests to reflect changes * Update createFormControl.ts * Update iterateFieldsByAction.ts * Update iterateFieldsByAction.test.ts --------- Co-authored-by: Beier (Bill) <[email protected]>
1 parent 4549afd commit 52611a5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

β€Žsrc/__tests__/logic/iterateFieldsByAction.test.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import iterateFieldsByAction from '../../logic/iterateFieldsByAction';
22

3-
describe('focusFieldBy', () => {
3+
describe('iterateFieldsByAction', () => {
44
it('should focus on the first error it encounter', () => {
55
const focus = jest.fn();
66
iterateFieldsByAction(

β€Žsrc/logic/createFormControl.tsβ€Ž

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,13 +1098,16 @@ export function createFormControl<
10981098
iterateFieldsByAction(
10991099
_fields,
11001100
(ref, name) => {
1101-
let requiredDisabledState = disabled;
1102-
const currentField = get(_fields, name);
1103-
if (currentField && isBoolean(currentField._f.disabled)) {
1104-
requiredDisabledState ||= currentField._f.disabled;
1101+
const currentField: Field = get(_fields, name);
1102+
if (currentField) {
1103+
ref.disabled = currentField._f.disabled || disabled;
1104+
1105+
if (Array.isArray(currentField._f.refs)) {
1106+
currentField._f.refs.forEach((inputRef) => {
1107+
inputRef.disabled = currentField._f.disabled || disabled;
1108+
});
1109+
}
11051110
}
1106-
1107-
ref.disabled = requiredDisabledState;
11081111
},
11091112
0,
11101113
false,

0 commit comments

Comments
Β (0)