Skip to content

Commit

Permalink
fix(MenuItem): QUV-1108 Avoid adding extra space to the left, based i…
Browse files Browse the repository at this point in the history
…n a new state 'active' and in presence of selectionScheme prop
  • Loading branch information
soslayando committed Jun 8, 2023
1 parent f50d5b5 commit 82d1b99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ export const Selectable: Story = {
})(),
};

export const ActiveForNavigation: Story = {
name: 'Active for navigation',
render: () =>
(() => {
const [active, setActive] = React.useState(false);
const onOptionClick = () => setActive(!active);
return (
<Menu.Item
label="Option one"
onClick={onOptionClick}
state={active ? 'active' : 'enabled'}
/>
);
})(),
};

export const CustomContent: Story = {
render: () =>
(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export const MenuItem: React.FC<MenuItemProps> = ({
: selectionScheme === 'multiple'
? 'menuitemcheckbox'
: 'menuitem';
const hasExtraLeftSpaceEval =
(hasExtraLeftSpace ||
Boolean(icon) ||
isSelectable ||
Boolean(selectionScheme)) &&
!Boolean(children);

return (
<StyledMenuItem as={as}>
<StyledMenuItemInner
Expand All @@ -120,10 +127,7 @@ export const MenuItem: React.FC<MenuItemProps> = ({
as={isLink ? 'a' : isSelectable ? 'label' : 'button'}
disabled={!isLink && !isSelectable && isDisabled}
download={download}
hasExtraLeftSpace={
(hasExtraLeftSpace || Boolean(icon) || isSelectable) &&
!Boolean(children)
}
hasExtraLeftSpace={hasExtraLeftSpaceEval}
href={isDisabled ? null : href}
id={id}
name={isSelectable ? null : name}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { css } from 'styled-components';
import {
ActiveState,
BasicState,
ButtonAttrProps,
ExpandedState,
Expand Down Expand Up @@ -28,6 +29,7 @@ export interface StyledMenuItemInnerProps
/** State of the menu item */
state?:
| BasicState
| ActiveState
| MouseState
| FeaturedState
| SelectedState
Expand All @@ -37,6 +39,7 @@ export interface StyledMenuItemInnerProps

export const StyledMenuItemInner = styled.button<StyledMenuItemInnerProps>`
${({ hasExtraLeftSpace, state = 'enabled', theme, unlimitedHeight }) => {
const stateForTokens = state === 'active' ? 'activated' : state;
const aliasTokens = theme.alias;
const tokens = aliasTokens.menus.item;
const horPadding = menuItemSizeConfig(theme).horPadding;
Expand All @@ -60,8 +63,8 @@ export const StyledMenuItemInner = styled.button<StyledMenuItemInnerProps>`
${aliasTokens.mutation.transitionDuration.action};
height: ${unlimitedHeight ? 'auto' : tokens.size.minHeight};
padding: ${unlimitedHeight ? horPadding : `0 ${horPadding}`};
background-color: ${tokens.color.background[state]};
color: ${tokens.color.text[state]};
background-color: ${tokens.color.background[stateForTokens]};
color: ${tokens.color.text[stateForTokens]};
cursor: pointer;
text-decoration: none;
Expand Down Expand Up @@ -109,7 +112,7 @@ export const StyledMenuItemInner = styled.button<StyledMenuItemInnerProps>`
${(state === 'expanded' || state === 'hovered' || state === 'pressed') &&
css`
&&& {
${menuItemBackdropMixin({ tokens, state })};
${menuItemBackdropMixin({ tokens, state: stateForTokens })};
}
`}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/declarations/commonProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export type ExpandedState = 'expanded';

export type FeaturedState = 'featured';

export type ActiveState = 'active';

export type ReadonlyState = 'readonly';

export type UIState = 'created' | 'deleted';
Expand Down

0 comments on commit 82d1b99

Please sign in to comment.