Skip to content
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

[TypeScript] Switch is missing keyboardFocused class key #10976

Closed
ianschmitz opened this issue Apr 9, 2018 · 15 comments
Closed

[TypeScript] Switch is missing keyboardFocused class key #10976

ianschmitz opened this issue Apr 9, 2018 · 15 comments
Assignees
Labels
good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request typescript

Comments

@ianschmitz
Copy link
Contributor

Looks like the definition for Switch or one of its inherited definitions was updated recently which removed the keyboardFocused class key.

I wonder if SwitchBase's SwitchBaseClassKey definition should also include IconButtonClassKey?
https://github.com/mui-org/material-ui/blob/466c01fc7e7bc76adf5ad34da125daff43a1b206/src/internal/SwitchBase.d.ts#L23

@ianschmitz
Copy link
Contributor Author

There may be more to it actually. When using [email protected] I receive a console error when trying to use the keyboardFocused class key when rendering an IconButton:

Warning: Material-UI: the key `keyboardFocused` provided to the classes property is not implemented in IconButton.
You can only override one of the following: root,colorInherit,colorPrimary,colorSecondary,disabled,label

However the TypeScript definitions are happy for me to provide a keyboardFocused class key in my IconButton.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 9, 2018

I wonder if SwitchBase's SwitchBaseClassKey definition should also include IconButtonClassKey?

@ianschmitz No, it shouldn't. The classes isn't inherited between the React elements like the properties are. Should we change this behavior? I have been wondering about it over the last weeks. I don't know. I like how the classes object impact is scoped and how it as few side effects. I'm not sure CSS inheritance + classes object inheritance will make things simpler.

Going back to your issue. Do you need the keyboardFocused class name on the Switch element?

@ianschmitz
Copy link
Contributor Author

Yes a keyboardFocused class name on the Switch would be awesome.

With regards to the inheritance, i was under the assumption that the inherited classes would flow through to the rendered component. i.e. IconButtonClassKey inherites the ButtonBaseClassKey, so i assumed that any ButtonBase classes I defined would be passed through to the rendered ButtonBase.

I agree that the classes scoping is nice. My sense is that if that's the pattern we want to follow, we shouldn't be combining the class key definitions of child components, as it can cause errors such as the one i experienced with keyboardFocused.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 9, 2018

@ianschmitz It sounds like:

  1. we need to clean the type definition that wrongly defines the keyboardFocused class key.
  2. we gonna need to reintroduce a keyboardFocusedClassName property. It might also be time to look for a better naming if possible. It's the same feature as: https://github.com/WICG/focus-visible.

@oliviertassinari oliviertassinari added the new feature New feature or request label Apr 9, 2018
@ianschmitz
Copy link
Contributor Author

Would it be reasonable to add keyboardFocused to the Switch classes? I just mention cause I've seen a few PRs that were trying to get rid of the xxxClassName properties.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 9, 2018

Would it be reasonable to add keyboardFocused to the Switch classes? I just mention cause I've seen a few PRs that were trying to get rid of the xxxClassName properties.

@ianschmitz I'm happy with this too, but you need to add it to all the components along the chain: Switch > SwitchBase > IconButton. This is going to be quite some boilerplate.
I'm also fine with doing an exception to the rule of removing the xxxClassName properties, keyboardFocused is an important state.

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Apr 9, 2018
@ianschmitz
Copy link
Contributor Author

I'm happy either way. Thanks @oliviertassinari !

I agree keyboard focused states are super useful. We can do some pretty nifty styling with it. We were able to completely redesign the styling of MUI's Switch component to put our own touch on it, while still keeping the awesome API of MUI. For example here is our switch with the first one currently keyboard focused:

image

@ianschmitz
Copy link
Contributor Author

ianschmitz commented Apr 9, 2018

@ianschmitz It sounds like:

we need to clean the type definition that wrongly defines the keyboardFocused class key.
we gonna need to reintroduce a keyboardFocusedClassName property. It might also be time to look for a better naming if possible. It's the same feature as: https://github.com/WICG/focus-visible.

To clarify this, both the Switch and IconButton need the keyboard focused state.

@ianschmitz
Copy link
Contributor Author

@oliviertassinari I think this issue is a little more wide spread than I initially thought. I just tried using MenuItem's classes prop to specify keyboardFocused. TypeScript thinks this exists since MenuItem inherits ListItemClassKey, however at runtime this presents an error:

Warning: Material-UI: the key `keyboardFocused` provided to the classes property is not implemented in MenuItem.
You can only override one of the following: root,selected

In the case of MenuItem I'm stuck since there is no ListItemProps that i could use to pass in clases to ListItem. I suspect this may the case elsewhere.

@oliviertassinari oliviertassinari added this to the release of v1.0.0 milestone Apr 17, 2018
@oliviertassinari
Copy link
Member

@ianschmitz I'm adding this issue to the v1 milestone. We need to sort that out before the stable release. We might need to introduce a breaking change.

@dmythro
Copy link

dmythro commented Apr 24, 2018

@oliviertassinari, this broke the behavior of lots of parts of our application.
Basically, we need the same keyboard focused for each component who can receive focus: Button, ButtonBase, IconButton, ListItem, MenuItem etc. And it is required by the Accessibility - to have clear visible focus from the keyboard navigation.

Property/classes related change is not appropriate as it should behave/look the same on the whole application and possible to do with theme/overrides or something like that.

If there is another issue already created please link it here - I'll follow there.

@oliviertassinari
Copy link
Member

Property/classes related change is not appropriate as it should behave/look the same on the whole application and possible to do with theme/overrides or something like that.

@Z-AX I see your point. Of course you could wrap each component. But a theme.overrides.MuiButtonBase.focusVisible would be simpler. Do you want to work on that?

@dmythro
Copy link

dmythro commented Apr 24, 2018

@oliviertassinari actually, I'm more into the focusVisible. But as briefly refactored to focusVisible from keyboardFocused in theme creation see that it's not applied everywhere (BaseButton/IconButton is not affected at least from what I see). Or it is? Or, maybe, there is a possible way to override it in a single place? Basically, we're just setting the custom outline for this. Probably would be nice to remove ripple layout as it sticks now on focused button and reduces the contrast (which also may be bad for ADA/Accessibility).

@dmythro
Copy link

dmythro commented Apr 24, 2018

By removing ripple I mean this case which sticks while focus on the component, not removed anyhow with time:
image
image

@dmythro
Copy link

dmythro commented Apr 24, 2018

But at least I want the consistent outline, reused everywhere :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request typescript
Projects
None yet
Development

No branches or pull requests

3 participants