-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Support Indeterminate checkboxes #5908
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
Conversation
@@ -477,6 +477,7 @@ ReactDOMComponent.Mixin = { | |||
ReactDOMInput.mountWrapper(this, props, nativeParent); | |||
props = ReactDOMInput.getNativeProps(this, props); | |||
transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this); | |||
transaction.getReactMountReady().enqueue(ReactDOMInput.initializeIndeterminate, this); |
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.
this could be theoretically handled more generally, by having something loop through props propertyInfo and checking for IDL only attributes and setting them. Perhaps that would be more efficient? My assumption is that the above will properly batch everything anyway so it may not matter.
@spicyj It has been a week, can you take a look at this? |
I've been looking back at other issues with non content attributes: #2140, #2094 (comment), and the idea of supporting them seems fairly negative, so maybe this falls into the category as well (although the discussion in #1798 was more hopeful). It seems like this case, at least, fits more easily into a declarative model. I'd be happy to rebase if anyone thinks this is a reasonable approach. |
ping! |
I think this is a really tricky subject. React supporting non-attribute properties plays badly with SSR (not that you can avoid it) and it opens up a whole new area of what else. A redeeming factor here is that it is at least local to It should be possible to implement this as a user-land wrapper component instead, which may be a better short-term (or even long-term) solution until there is a decision on the larger discussion of where to draw the line on this I think? |
(cc @azich too) |
I agree that is tricky :) I thought that this case in particular was a good one to discuss that line a bit, and explore some of the issues and possibilities. In this case I think unlike some other non-content attributes it feels like indeterminate, could have easily been an attribute, so there isn't as much to hem and haw about in terms of a declarative api. The There are some clear limitations here, with regard to SSR. Although they are isolated to cases using |
I have very mixed feelings about this one. Ultimately, I think @syranide is right. This opens a large can of worms. At least for now, this is probably better handled in user land by providing a custom component. This doesn't merge cleanly, and there is no clear path forward, so let's close this out for now. We can come back to this if/when our thinking on this matter changes. |
Adds support for setting
indeterminate
ordefaultIndeterminate
props on checkbox elements. The tricky bit was properly setting the initial state from existing markup sinceindeterminate
is not a content attribute. To that end I added a new IDL Only Attribute flag for DOM properties that does not generate any additional markup for said properties. In addition ReactDOMInput is responsible for setting the initial state based on props at mount.I went with a controlled/uncontrolled approach for the API since that seemed like the most straight forward, and keeps the coupling to
checked
to a minimum. I am not sure if the caveat about browser behavior differences mentioned in #1798, exists but it's an easy fix to toggle indeterminate to false onChange in the uncontrolled case.closes #1798