-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply disabled fix when inside a disabled fieldset
And if we are in a disabled fieldset, double check that we are not in the first legend. Because in that case we are visually outside of the fieldset and according to the spec those elements should **not** be considered disabled. Fixes: #194
- Loading branch information
1 parent
de16c1b
commit bf15fcd
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// See: https://github.com/facebook/react/issues/7711 | ||
// See: https://github.com/facebook/react/pull/20612 | ||
// See: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-disabled (2.) | ||
export function isDisabledReactIssue7711(element: Element): boolean { | ||
let parent = element.parentElement | ||
let legend = null | ||
|
||
while (parent && !(parent instanceof HTMLFieldSetElement)) { | ||
if (parent instanceof HTMLLegendElement) legend = parent | ||
parent = parent.parentElement | ||
} | ||
|
||
let isParentDisabled = parent?.getAttribute('disabled') === '' ?? false | ||
if (isParentDisabled && isFirstLegend(legend)) return false | ||
|
||
return isParentDisabled | ||
} | ||
|
||
function isFirstLegend(element: HTMLLegendElement | null): boolean { | ||
if (!element) return false | ||
|
||
let previous = element.previousElementSibling | ||
|
||
while (previous !== null) { | ||
if (previous instanceof HTMLLegendElement) return false | ||
previous = previous.previousElementSibling | ||
} | ||
|
||
return true | ||
} |