-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Dropdown: Add wrapper for custom padding #42595
Conversation
import { | ||
more, | ||
arrowLeft, | ||
arrowRight, | ||
arrowUp, | ||
arrowDown, | ||
} from '@wordpress/icons'; |
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 had to do some basic cleanup of the story first. It may be easier to review the commits separately.
Size Change: +146 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
Here's what I'm seeing: padding.mp4
It's working well for me. |
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.
LGTM 🚀
PS: the new story revealed some weird behaviors:
- the layout on small viewports looks a bit weird when
expandOnMobile
istrue
- the
headerTitle
is only shown on mobile viewports whenexpandOnMobile
istrue
(it's documented in the README, but it's still a bit weird)
✅ Styling bug with |
Follow-up to #41937, #41900
What?
Adds a
<DropdownContentWrapper>
subcomponent for managing different padding values in theDropdown
content.Why/How?
We have encountered many ad hoc overrides of the Dropdown content padding, which involve reaching into internal CSS classes (
.components-popover__content
).Size scale
A survey of all the padding overrides in the codebase showed that almost all these instances wanted either a padding value of 16px or 0 (default is 8px). The only two exceptions were rather arbitrary values, not adhering to the 4px grid system.
This suggests that we can abstract this to some padding presets. There is an existing padding size scale used in
Card
, but I'm hesitant to adopt the same scale because the context is different. I'm leaning toward a scale that is specific to Dropdown usage, but this is up for discussion.My tentative proposal is
small=8px
(default),medium=16px
, andnone=0
.Prop or subcomponent
The other main decision we need to make is whether to add a root-level
contentPaddingSize
prop, or to add a wrapper subcomponent.Root-level props are seemingly simpler, but always come with the slippery slope risk of cluttering up the root component with increasingly niche props. Subcomponents are safer in that regard, as it will be a good vessel to add more content-related props in the future.
That said, the main reason I'm leaning toward a subcomponent in this case because we are seeing a high number of anti-patterns where the consumer is setting dimension styles (e.g.
min-width
) directly on.components-popover__content
. This is easily avoidable by using their own wrapper div on the dropdown content. By providing an "official" wrapper component, maybe we can further encourage consumers to set styles on wrappers instead of reaching into internal CSS classes.Testing Instructions
1.
npm run storybook:dev
and see the stories forDropdown
.