Skip to content

Commit

Permalink
fix(menu): focused menu items missing styles (#3107)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiTaggart committed Mar 21, 2023
1 parent 05461df commit b47e131
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/quiet-hats-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/menu': patch
'@twilio-paste/core': patch
---

[Menu] fix focus styles on menu items since design updates
33 changes: 19 additions & 14 deletions packages/paste-core/components/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
import * as React from 'react';
import {secureExternalLink} from '@twilio-paste/anchor';
import {Box, safelySpreadBoxProps} from '@twilio-paste/box';
import type {BoxStyleProps} from '@twilio-paste/box';
import {MenuPrimitiveItem} from '@twilio-paste/menu-primitive';

import type {MenuItemProps, MenuItemVariant} from './types';
import type {MenuItemProps, MenuItemVariantStyles} from './types';
import {MenuGroupContext} from './MenuGroup';
import {MenuItemVariants} from './constants';

const variantStyles: Record<MenuItemVariant, BoxStyleProps> = {
const baseVariantStyles: MenuItemVariantStyles = {
[MenuItemVariants.DEFAULT]: {
color: 'colorText',
_hover: {
color: 'colorTextPrimary',
backgroundColor: 'colorBackgroundPrimaryWeakest',
borderColor: 'colorBorderPrimary',
},
_focus: {
color: 'colorTextPrimary',
backgroundColor: 'colorBackgroundPrimaryWeakest',
borderColor: 'colorBorderPrimary',
},
},
[MenuItemVariants.DESTRUCTIVE]: {
color: 'colorTextLinkDestructive',
_hover: {
backgroundColor: 'colorBackgroundDestructiveWeakest',
borderColor: 'colorBorderDestructive',
},
_focus: {
backgroundColor: 'colorBackgroundDestructiveWeakest',
borderColor: 'colorBorderDestructive',
},
},
};
const groupVariantStyles: MenuItemVariantStyles = {
[MenuItemVariants.GROUP_ITEM]: {
...baseVariantStyles[MenuItemVariants.DEFAULT],
paddingLeft: 'space90',
color: 'colorText',
_hover: {
color: 'colorTextPrimary',
backgroundColor: 'colorBackgroundPrimaryWeakest',
borderColor: 'colorBorderPrimary',
},
},
[MenuItemVariants.DESTRUCTIVE_GROUP_ITEM]: {
color: 'colorTextLinkDestructive',
...baseVariantStyles[MenuItemVariants.DESTRUCTIVE],
paddingLeft: 'space90',
_hover: {
backgroundColor: 'colorBackgroundDestructiveWeakest',
borderColor: 'colorBorderDestructive',
},
},
};
const variantStyles: MenuItemVariantStyles = {
...baseVariantStyles,
...groupVariantStyles,
};

export const StyledMenuItem = React.forwardRef<HTMLDivElement | HTMLAnchorElement, MenuItemProps>(
({element = 'STYLED_MENU_ITEM', href, variant = 'default', tabIndex, children, ...props}, ref) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/paste-core/components/menu/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ValueOf} from '@twilio-paste/types';
import type {BoxElementProps} from '@twilio-paste/box';
import type {BoxElementProps, BoxStyleProps} from '@twilio-paste/box';
import type {
MenuPrimitiveItemProps,
MenuPrimitiveProps,
Expand All @@ -12,6 +12,10 @@ export type MenuProps = MenuPrimitiveProps & {'aria-label': string; element?: Bo

export type MenuItemVariant = ValueOf<typeof MenuItemVariants>;

export type MenuItemVariantStyles = {
[key in MenuItemVariant]?: BoxStyleProps;
};

export interface MenuItemProps extends MenuPrimitiveItemProps {
href?: string;
element?: BoxElementProps['element'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ const MenuGroups = (): JSX.Element => {
</MenuGroup>
<MenuSeparator {...menu} />
<MenuGroup icon={<AttachIcon decorative />} label="Search Options">
<MenuItem {...menu}>Search with Google</MenuItem>
<MenuItem {...menu} variant="destructive">
Search with Google
</MenuItem>
<MenuItem {...menu} disabled>
Search with Bing
</MenuItem>
Expand Down

0 comments on commit b47e131

Please sign in to comment.