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

[withSwitchLabel] labelClassName vs className (LabelSwitch, LabelRadio, LabelCheckbox) #6746

Closed
Alxandr opened this issue May 1, 2017 · 9 comments
Assignees
Labels
bug 🐛 Something doesn't work component: checkbox This is the name of the generic UI component, not the React module! component: switch This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.
Milestone

Comments

@Alxandr
Copy link

Alxandr commented May 1, 2017

I'm writing an app using the next release of material-ui on npm, and for the most part it's really great. However I ran into one thing that puzzled me greatly today with the LabelSwitch. I wanted to move it up to the upper right corner, so I created a class witch had position: absolute; top: 5; right: 5 and used <LabelSwitch className='topRight' />, however only the switch was moved to the top right. I looked at the source and quickly discovered why (and how to fix it) using labelClassName, but I would argue that the outermost component should probably be styled using className, and that you could rather make a different switchClassName which targets the switch itself. All in all it's not the biggest of problems, I just feel that if you try to move a component you expect the entire component to move, not just a subcomponent.

@rosskevin
Copy link
Member

rosskevin commented May 2, 2017

Agreed, we have been discussing perhaps a different approach to complex components (perhaps under classes prop) and refining our use of them.

@nathanmarks @oliviertassinari - thoughts?

related: #6711

@rosskevin rosskevin added bug 🐛 Something doesn't work component: switch This is the name of the generic UI component, not the React module! next labels May 2, 2017
@rosskevin rosskevin changed the title [next] labelClassName vs className for LabelSwitch (and similar) [withSwitchLabel] labelClassName vs className (LabelSwitch, LabelRadio, LabelCheckbox) May 2, 2017
@rosskevin rosskevin added component: checkbox This is the name of the generic UI component, not the React module! component: RadioButton labels May 2, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented May 2, 2017

@Alxandr Thanks for trying out and sharing your experience with the next branch.
@rosskevin Sounds like you are experiencing the very same issue.

My thoughts on this. I see two issues.

Predictibility

  • This is quite an important API decision to make. Every single person using the library is going to face that issue.
  • We have an inconstancy between what's documented: the className always apply on the root element and what's implemented.
  • The inconstancy is privileging ease of use over predictability.
  • I would rather keep predictability by:
    • applying the className and the other properties on the root element.
    • providing a xxProps property for changing the properties of a nested xx element when that makes sense.

A very specific variation for a one-time problem/situation

We don't provide a theme property like react-toolbox is doing to customize every class names.
Instead, we expose class names, like the inputClassName className with the Input component.

After thinking about it, I think that exposing a classes property object, automatically documented would be better. Users would be able to customize everything at the class name level. That's deeply linked to the overrides key in the theme where users can override everything at the class level, not the instance level.
Actually, we have an issue for that #6137 :).

@Alxandr
Copy link
Author

Alxandr commented May 2, 2017

Slightly related: nathanmarks/jss-theme-reactor#42

That's another problematic control I found btw. Using Tabs inside an AppBar required this mess:

const styleSheet = createStyleSheet('RootAppBar', () => ({
  tabs: {
    height: '100%',

    '& > div': {
      height: '100%',

      '& > div': {
        height: '100%',

        '& > div:first-child': {
          height: '100%',
          alignItems: 'center',
        },
      },
    },
  },
}));

I can make another issue about the Tabs inside AppBar if wanted.

@oliviertassinari
Copy link
Member

@Alxandr The Tabs inside an AppBar is an interesting issue! I have faced it yesterday. I have been simply applying the height of the AppBar to the Tabs. Not the best solution. The height: 100% trick wasn't working for me on Safari. Noticed that you can now use the classes property to access nested elements.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 25, 2017

Back to this issue, I think that the best other alternative is exposing a SelectionLabel component on user-land instead of using a Higher-order component internally.

@oliviertassinari
Copy link
Member

I'm fine with both solutions (the current one and the proposed one). Let me know what you think :).

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Jun 16, 2017
@oliviertassinari
Copy link
Member

Any objection to expose a FormSwitchLabel component instead of a wrapping the base component with an HOC?

@rosskevin
Copy link
Member

No objections here

@oliviertassinari oliviertassinari modified the milestones: v1.0.0-prerelease, v1.0.0-beta Jul 4, 2017
@oliviertassinari oliviertassinari self-assigned this Jul 8, 2017
@oliviertassinari
Copy link
Member

I'm on it, let's follow rebass API, it's going to be a breaking change through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: checkbox This is the name of the generic UI component, not the React module! component: switch This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

No branches or pull requests

3 participants