-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Refactor switches, simplify code, fix related bugs. #5780
Refactor switches, simplify code, fix related bugs. #5780
Conversation
There is a |
@rosskevin Sounds good to me--also, I don't see the common use case for it outside of the list menus anyways, and for the material list menus, we do have a component that handles the list and placement already. |
9f9f56a
to
a31f23d
Compare
I like the code reduction. From regressions, it looks like components were column layout, now they are row layout. I've been meaning to PR, but this is a good time to discuss and get it in. I'd like consistency of Does this sound like a consistent/good addition to |
@rosskevin I think I didn't change anything that was explicitly setting a column layout. What I did do was change the I suppose my question is, why should column be the default for selection controls? And if we are doing that, we should enforce it via Also, at the moment, |
@nathanmarks I'm leaning towards labelled as the default export - my gut feeling is that unlabelled switches, such as the checkboxes in |
@mbrookes the labelled version actually works in tables, lists etc 😉 Just a tiny overhead by using it. |
|
@rosskevin I wasn't saying getting rid of the helper, I was just wondering about whether it had to be specific to forms or not. It looks super generic and could easily be made a HoC to give flex children styling to any component/element.
|
@nathanmarks - it is generic now, not generic later. Make sense? |
@rosskevin 100%, what did you have in mind for it? As in--what other layout problems for the forms is it going to help fix? Just curious/interested |
Did you miss my comment?
I have a wrapper around RadioGroup locally that integrates FormLabel. Would like to get this into core and do the same for FormGroup. Sorry if I confused you. |
@rosskevin Ahhh sorry. Missed the bit about the integration RE I think we need more flexibility here to keep concerns separated. What if |
Agree with that. FormGroup should be able to wrap FormLabel + RadioGroup and achieve the required spec behaviors for labels. |
Nice, that way |
I had Now label behavior is broken as I had coded it. The following label should be accented in this scenario (I clicked on the button): @nathanmarks your idea would solve this in a more elegant way (and leave @oliviertassinari's change as-is) |
@rosskevin The problem we had is that with the current RadioGroup and the JS based focus management, having the label inside completely broke the ability to tab into the widget and navigate through the radios. That's why it got removed from the demo. It should be super super easy to solve once this PR is ready. I'll try the idea I outlined above in a follow up PR. |
e6f45d9
to
6c0c097
Compare
- Refactors SwitchBase into a factory - Refactors Checkbox, Radio, Switch to use new Factory - Drastically simplify RadioGroup
6c0c097
to
58b47fd
Compare
58b47fd
to
bab90d4
Compare
@oliviertassinari let me know what you think |
The export could be confusing right now. Doing a default import is gonna have the
I had a close look at them. For what it worth, at @doctolib, we have been developing and using a simple homemade solution based on the #3614 discussion: LayoutBlock (still wip). |
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.
Cool to see how well the browser is taking care of the accessibility with the native input 👍
@@ -28,6 +28,7 @@ module.exports = { | |||
'no-console': 'error', // airbnb is using warn | |||
'no-param-reassign': 'off', | |||
'no-prototype-builtins': 'off', | |||
'no-use-before-define': ['error', { 'functions': false }], // airbnb have functions: true, annoying |
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.
I'm curious about the motivation.
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.
@oliviertassinari I wanted to put all the test helpers below the main part of the suite in one case. Functions are hoisted so there isn't any harm and in some scenarios it helps you leave more important stuff at the top. It isn't something that affects our react components because for the most part we have non-hoistables (class, assignment).
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.
Sounds like a fight between important stuff at the top vs load the context before digging into the code. I prefer the second option but some flexibility won't harm 👍 .
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.
Yeah, I see that side too -- but on the other hand it can be confusing to open a file and it's hard to find the root describe()
in a test because there's a bunch of helper functions first. In that case, you don't even know what they are for yet.
@@ -62,6 +62,7 @@ export const styleSheet = createStyleSheet('IconButton', (theme) => { | |||
export default function IconButton(props, context) { | |||
const { | |||
accent, | |||
buttonRef, |
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.
👍
@@ -1,34 +1,8 @@ | |||
// @flow weak | |||
// @flow weak |
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.
Space
@@ -121,6 +103,8 @@ export default class ButtonBase extends Component { | |||
button = null; | |||
keyboardFocusTimeout = undefined; | |||
|
|||
focus = () => this.button.focus(); |
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.
I think that we could have issue with this.button
being null when unmounting the tree. Not sure through. Will see in the long run.
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.
@oliviertassinari we could even remove this... although it's worth considering if it should be part of the public API so there is a react-based way to programatically focus our buttons. Unless you think that we should just recommend findDOMNOde
for now. WDYT?
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.
I don't know if findDOMNOde
is going to be removed or not.
I'm not sure how we are going to document that focus
imperative method.
I don't have much opinion. I would keep it for now as people might hit the eslint warning.
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.
@oliviertassinari I don't think it's being removed -- the question is more about what the right API to expose to our users is.
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.
I think that the imperative API is the best one. It's simpler to use to deprecated, to warn when not used correctly, it abstract the underlying dom implementation.
const switchComponentName = SwitchComponent.displayName || SwitchComponent.name; | ||
|
||
return class SwitchLabel extends Component { | ||
static displayName = `withSwitchLabel(${switchComponentName})`; |
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.
Could be using the recompose helper to set the display name:
https://github.com/acdlite/recompose/blob/master/src/packages/recompose/createHelper.js
@oliviertassinari I'm going to use |
6da2cf8
to
cd1978a
Compare
Just noticed a small focus related issue somewhere else that switches are used (lists). Fixing that. |
@rosskevin I ended up leaving |
@nathanmarks are you still going to pr a change to |
[wip] Still a couple of things to solidify 100% (and get the keyboard focus styles working for the switches)
name=""
.The changes here allow us to simplify the code significantly with regards to everything from accessibility, complexity related to implementing native-like keyboard functionality, duplicated code, and more.
@oliviertassinari @mbrookes a few questions:
cc @rosskevin:
I've removed
labelReverse
here. I can't find a single common use case in an RTL language to justify it being part of core. It's just single flex property so think it should be done in userland. WDYT?