Skip to content

Commit 1346823

Browse files
committed
🐛 fix: fix dropdown options container z-index on close
1 parent 9d0ac8f commit 1346823

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/compositions/Dropdown/DropdownWithTags.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type DropdownWithTagsProps = Omit<PartialDropdownProps, 'initialSelected'
2828
/** A custom renderer for the tags */
2929
tag?: RenderFromPropElement<DropdownWithTagsOption>;
3030
tagGroupProps?: Omit<TagGroupProps, 'size'>;
31+
/** The margin between the tag group and the dropdown */
32+
tagMarginTop?: number;
3133
tagProps?: Omit<TagProps<'button'>, 'actionable' | 'as' | 'children' | 'onClick' | 'ref'>;
3234
tagShape?: TagShape;
3335
tagSize?: TagSize;
@@ -61,6 +63,7 @@ export function DropdownWithTags({
6163
tagProps,
6264
tagShape = 'pill',
6365
tagSize = 'xsmall',
66+
tagMarginTop = 6,
6467
tagWeight = 'outlined',
6568
themeId: initThemeId,
6669
translations: customTranslations,
@@ -166,7 +169,7 @@ export function DropdownWithTags({
166169
themeId={themeId}
167170
{...props}
168171
/>
169-
<Rhythm grouped mt={6}>
172+
<Rhythm grouped mt={tagMarginTop}>
170173
<TagGroup size={tagSize} {...tagGroupProps}>
171174
{options
172175
.filter(({ id }) => state.selectedIds.includes(id))

src/compositions/Dropdown/stories/DropdownWithTags.stories.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export default {
8484
category: 'Tags',
8585
},
8686
},
87+
tagMarginTop: {
88+
table: {
89+
category: 'Tags',
90+
},
91+
},
8792
tagGroupProps: {
8893
table: {
8994
category: 'Tags',

src/compositions/Dropdown/styles/Dropdown.module.css

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
}
3131
}
3232

33+
/**
34+
* 1. Prevent the dptions container from falling behind
35+
the tags (if applicable) while it's closing.
36+
*/
3337
.dropdownOptionsContainer {
3438
left: 0;
3539
overflow: visible;
@@ -38,6 +42,10 @@
3842
top: 100%;
3943
user-select: none;
4044

45+
&:not(.is-visible) {
46+
z-index: 2; /* [1] */
47+
}
48+
4149
&.is-visible {
4250
z-index: $layout-z-index-popover;
4351

src/stories/Playground.stories.mdx

+12-8
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ import {
652652
{ id: 4, value: 'four' },
653653
{ id: 5, value: 'five', label: 'Plain text option' },
654654
].map(option => ({
655-
label: ({ selected }) => (
655+
label: ({ focused, selected }) => (
656656
<Flex flexible alignItems="center" direction="row" justifyContent="flex-start">
657657
<Avatar
658658
imgSrc="/images/avatar.png"
@@ -664,9 +664,11 @@ import {
664664
<Typography weight="bold">Phorkish</Typography>
665665
</Flex>
666666
</Rhythm>
667-
<Typography color={selected ? 'contrast' : 'accent'} variants="line-height-smash">
668-
<CheckIcon scale="medium" />
669-
</Typography>
667+
{selected && (
668+
<Typography color={focused ? 'contrast' : 'accent'} variants="line-height-smash">
669+
<CheckIcon scale="medium" />
670+
</Typography>
671+
)}
670672
</Flex>
671673
),
672674
selectedLabel: option.label || (
@@ -730,7 +732,7 @@ import {
730732
{ id: 4, value: 'four' },
731733
{ id: 5, value: 'five', label: 'Plain text option' },
732734
].map(option => ({
733-
label: ({ selected }) => (
735+
label: ({ focused, selected }) => (
734736
<Flex flexible alignItems="center" direction="row" justifyContent="flex-start">
735737
<Avatar
736738
imgSrc="/images/avatar.png"
@@ -746,9 +748,11 @@ import {
746748
</Typography>
747749
</Flex>
748750
</Rhythm>
749-
<Typography color={selected ? 'contrast' : 'accent'} variants="line-height-smash">
750-
<CheckIcon scale="medium" />
751-
</Typography>
751+
{selected && (
752+
<Typography color={focused ? 'contrast' : 'accent'} variants="line-height-smash">
753+
<CheckIcon scale="medium" />
754+
</Typography>
755+
)}
752756
</Flex>
753757
),
754758
selectedLabel: option.label || (

0 commit comments

Comments
 (0)