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

fix(Dropdown): rely on list-box height closes #4916 #4917

Closed
wants to merge 6 commits into from

Conversation

vpicone
Copy link
Contributor

@vpicone vpicone commented Dec 18, 2019

Testing: test all the possible sizes for dropdown using the storybook knob

  • also check vanilla ;)

Dropdown isn't implemented as a listbox in vanilla but is in React. In React we rely on the list box height for things like size. Vanilla can't rely on listbox height so we define it here.

@vpicone vpicone requested a review from a team as a code owner December 18, 2019 21:44
@ghost ghost requested review from abbeyhrt and asudoh December 18, 2019 21:44
@netlify
Copy link

netlify bot commented Dec 18, 2019

Deploy preview for the-carbon-components ready!

Built with commit 5e4da0b

https://deploy-preview-4917--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Dec 18, 2019

Deploy preview for carbon-components-react ready!

Built with commit 5e4da0b

https://deploy-preview-4917--carbon-components-react.netlify.com

@netlify
Copy link

netlify bot commented Dec 18, 2019

Deploy preview for carbon-elements failed.

Built with commit 5e4da0b

https://app.netlify.com/sites/carbon-elements/deploys/5dfac41ab505d300084daa15

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropdown appear broken in vanilla

@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@alisonjoseph vanilla is actively making our code worse, someone put it out of its misery.

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for jumping in @vpicone - Vanilla dropdown doesn't have .bx--list-box, which will be more solid distinction than detecting ARIA role (given vanilla dropdown may add ARIA role in future).

UPDATE: I see what the problem is all about - Selector specify problem. I think the best fix is changing the selector of height rulesets to e.g.: .bx--list-box.bx--list-box--xl

.#{$prefix}--dropdown:not(.#{$prefix}--list-box) {
height: rem(40px);
}

.#{$prefix}--dropdown--xl {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asudoh can you explain what these were added for?

@vpicone vpicone requested a review from asudoh December 18, 2019 23:14
@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@asudoh The problem, as you mentioned, is the lack of list-box styles in Vanilla. My first solution was to remove the height from Dropdown (because it's defined by list-box), however this means Vanilla has no height and breaks.

More specificity is not the correct way about this. That makes it even more difficult for someone to theme/style this component. We would need to add extra specificity to all the list box components, not just the Dropdown.

I updated the solution to use a class rather than role.

@asudoh
Copy link
Contributor

asudoh commented Dec 18, 2019

I still think the problem is selector specificity, because if you take a look at the Styles tab in Chrome DevTools, we see .bx--dropdown (the class for regular list box) overrides the height even though .bx--list-box-xl sets the height for the specific size variant, which tells the definition order of .bx--dropdown and .bx--list-box-xl is in play. We need to ensure things work regardless of the definition order. Application can still override the style with the new selector (.bx--list-box.bx--list-box--xl).

Vanilla dropdown not having .bx--list-box came from a historical reason, which is, the divergence of the markup between vanilla and React.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@asudoh the instructions you gave are the same ones I gave in the issue I opened. The overall issue here is the dropdown styles are competing with the listbox styles.

The best solution is to remove the height from Dropdown (my first solution). This doesn't work because Vanilla can't use listbox height. So that gives us these options:

  1. Do we make the styles for all listbox components more specific to override just the dropdown components height? (your proposal).
  2. Do we provide a height when one isn't provided by list-box without creating more specificity (my current solution).

If we use your solution, someone styling our component would need to use two classes just to match the specificity you're proposing. In addition that impacts Multiselect, Combobox AND Dropdown for all frameworks.

@asudoh
Copy link
Contributor

asudoh commented Dec 18, 2019

I see specificity race is not about dropdown vs. list box. It's rather about default height of the list box vs. specific size variant of list box, and making sure the size variant works regardless of ruleset definition order. BTW :not(.bx--list-box) adds specificity to regular version of dropdown for vanilla.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@asudoh correct, it adds specificity to a single framework for a single component.

Your solution adds specificity for all list box components in all frameworks.

@asudoh
Copy link
Contributor

asudoh commented Dec 18, 2019

The important thing is about "regular version". If we add specificity to the regular version, specificity of specific variants will be affected.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@asudoh those variants would be written only for vanilla? It seems that's what you were attempting to do with the bx--dropdown-xl stuff. We definitely don't want to write variants for a single framework...

@asudoh
Copy link
Contributor

asudoh commented Dec 18, 2019

No, those variant are both for vanilla/React.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 18, 2019

@asudoh you didn't use those classes in your PR. The prop you implemented specifically impacts ListBox

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

The problem is that a change to selector order (among components) seems to have happened after the dropdown size variant change is checked in, and thus I didn't notice (potential at then) selector order/specificity problem when I implemented it.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

@asudoh this problem existed in the preview for your PR.

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

Sounds strange, sorry then. Probably the bug was introduced to when I coped with review comments.

UPDATE: I now see the issue with Netlify preview was likely to have been caused by rebasing. The dropdown size variant PR was created 29 days ago, and a change that is likely to have changed the ruleset definition order in question was merged 26 days ago.

@alisonjoseph
Copy link
Member

UPDATE: I now see the issue with Netlify preview was likely to have been caused by rebasing.

Agree, this must be what happened, I can't imagine everyone would have approved the PR, design included otherwise.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

@alisonjoseph the only thing that was broken was dropdown xl. dropdown sm and the other listbox components worked. I can definitely see how it was overlooked.

Regardless of how it was caused, I think this is the best way forward.

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

I suggest making size variants work regardless of selector definition order, instead of patching to .bx--dropdown selector.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

@asudoh my solution eliminates the order problem by deleting the height off of the drop down. It only supply’s the height when it’s not defined by the list box class.

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

The problem with .bx--dropdown:not(.bx--list-box) kind of selector is that it increases the specificity of regular dropdown.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

@asudoh your solution increases the specificity of not just drop down but all listbox components. 3 components on all frameworks. This rule only applies to drop downs which are not list boxes (vanilla) 1 component 1 framework.

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

@asudoh your solution increases the specificity of not just drop down but all listbox components. 3 components on all frameworks.

The increased specificity is how the selectors should have been defined, to make sure we override the default height if it's defined (or application defines the default height).

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

@asudoh I disagree. We don’t define the height for the other list box component. Increasing their specificity needlessly would be a bad decision.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

Important disagreement in what you just said: we should never implement a feature by trying to overcome/exert styles with extra specificity. That results in fragile, difficult to theme styles.

@asudoh
Copy link
Contributor

asudoh commented Dec 19, 2019

CSS specificity is used to ensure the more specific the selector is, the more the associated CSS rules are prioritized. Therefore, exact use case for size variants.

@vpicone
Copy link
Contributor Author

vpicone commented Dec 19, 2019

Alright @asudoh , I look forward to your fix! We’re waiting on the large drop down for the website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants