Skip to content

Commit

Permalink
Fix dropdown menu header (#4835)
Browse files Browse the repository at this point in the history
Fix an issue I add introduced by removing "position:static" and an other
regression from #4366
  • Loading branch information
FelixMalfait authored Apr 5, 2024
1 parent b825193 commit 3df4b78
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentProps, MouseEvent } from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';

import { IconComponent } from '@/ui/display/icon/types/IconComponent';
Expand All @@ -7,25 +8,38 @@ import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
const StyledHeader = styled.li`
align-items: center;
color: ${({ theme }) => theme.font.color.primary};
cursor: pointer;
cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')};
display: flex;
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
border-radius: ${({ theme }) => theme.border.radius.sm};
border-top-left-radius: ${({ theme }) => theme.border.radius.sm};
border-top-right-radius: ${({ theme }) => theme.border.radius.sm};
padding: ${({ theme }) => theme.spacing(1)};
user-select: none;
`;
const StyledChildrenWrapper = styled.span`
padding: 0 ${({ theme }) => theme.spacing(1)};
&:hover {
background: ${({ theme, onClick }) =>
onClick ? theme.background.transparent.light : 'none'};
}
`;

const StyledLightIconButton = styled(LightIconButton)`
const StyledEndIcon = styled.div`
display: inline-flex;
color: ${({ theme }) => theme.font.color.tertiary};
padding: ${({ theme }) => theme.spacing(1)};
margin-left: auto;
margin-right: 0;
& > svg {
height: ${({ theme }) => theme.icon.size.md}px;
width: ${({ theme }) => theme.icon.size.md}px;
}
`;

const StyledChildrenWrapper = styled.span`
padding: 0 ${({ theme }) => theme.spacing(1)};
`;

type DropdownMenuHeaderProps = ComponentProps<'li'> & {
Expand All @@ -42,27 +56,29 @@ export const DropdownMenuHeader = ({
onClick,
testId,
}: DropdownMenuHeaderProps) => {
const theme = useTheme();
return (
<StyledHeader data-testid={testId}>
{StartIcon && (
<LightIconButton
onClick={onClick}
testId="dropdown-menu-header-end-icon"
Icon={StartIcon}
accent="tertiary"
size="small"
/>
)}
<StyledChildrenWrapper>{children}</StyledChildrenWrapper>
<>
{EndIcon && (
<StyledLightIconButton
onClick={onClick}
testId="dropdown-menu-header-end-icon"
Icon={EndIcon}
accent="tertiary"
size="small"
/>
<StyledHeader data-testid={testId} onClick={onClick}>
<StyledChildrenWrapper>{children}</StyledChildrenWrapper>
<StyledEndIcon>
<EndIcon size={theme.icon.size.md} />
</StyledEndIcon>
</StyledHeader>
)}
{StartIcon && (
<StyledHeader data-testid={testId}>
<LightIconButton
testId="dropdown-menu-header-end-icon"
Icon={StartIcon}
accent="tertiary"
size="small"
onClick={onClick}
/>
<StyledChildrenWrapper>{children}</StyledChildrenWrapper>
</StyledHeader>
)}
</StyledHeader>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const StyledHoverableMenuItemBase = styled(StyledMenuItemBase)<{
& .hoverable-buttons {
opacity: 1;
pointer-events: auto;
position: static;
}
}
`;

0 comments on commit 3df4b78

Please sign in to comment.