-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
apply disabled fix when inside a disabled fieldset #202
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick, but shouldn’t you return false if first legend no matter if in a disabled fieldset or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should result in the same behaviour:
Because, when the
isParentDisabled
is false, then the result will befalse
anyway. So at this point it doesn't really matter that we are in alegend
or not. The edge case is that when the parent is disabled but we are in the first legend, then we should ignore that.Here is a truth table:
true
true
false
true
false
true
else
case is executed which is the result ofisParentDisabled
.false
true
false
else
case is executed which is the result ofisParentDisabled
.false
false
false
else
case is executed which is the result ofisParentDisabled
.I think that this is the correct behaviour 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being unclear. I was on my phone with limited time (and UX...).
I wasn't implying it was incorrect (which is why I considered it a nitpick), merely that the code could possibly be slightly simplified/refactored to:
Rationale: if it's in the first legend it should always return
false
, no matter where it is in the DOM or if it's enclosingfieldset
is disabled.Running it by your truth table yields the same result, as far as I can tell.
Not saying you should change it necessarily, you might find the current implementation more clear. Just throwing it out there how I see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yep, I see what you mean.
I tried to follow the wording of the spec (but it is not that readable in the spec (2.))
But in the end, I don't think it matters much. Ideally we remove the code once React itself is fixed.