Skip to content
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

feat(Menu): set new default for menu trigger #1965

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/Button/Button-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
align-items: center;
justify-content: center;

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

width: 100%;

.button--sm & {
Expand All @@ -33,6 +37,10 @@
.button--lg & {
gap: 0.5rem;
}

& svg {
flex-shrink: 0;
}
}

.button__text.button--is-loading {
Expand Down
1 change: 1 addition & 0 deletions src/components/Menu/Menu-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}

.menu__item {
display: block;
text-decoration: none;
color: inherit;
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Menu/Menu-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const Default: StoryObj<MenuProps> = {
},
};

/**
* Be careful when using a lot of text for a menu trigger. The UI will force the text out of the button container. Use brief text for menu triggers.
*/
export const WithLongButtonText: StoryObj<MenuProps> = {
args: {
children: (
Expand Down
20 changes: 10 additions & 10 deletions src/components/Menu/Menu-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { usePopper } from 'react-popper';

import type { ExtractProps } from '../../util/utility-types';

import Button from '../Button';
import { IconV2 as Icon, type IconNameV2 as IconName } from '../Icon';
import { ButtonV2 as Button } from '../Button';
import { type IconNameV2 as IconName } from '../Icon';

import {
PopoverContainerV2 as PopoverContainer,
Expand Down Expand Up @@ -54,7 +54,7 @@ export type MenuButtonProps = {
/**
* The button contents placed left of the chevron icon.
*/
children: ReactNode;
children: string;
/**
* Allow custom classes to be applied to the menu button.
*/
Expand Down Expand Up @@ -126,14 +126,14 @@ const MenuButton = ({

return (
<HeadlessMenu.Button as={React.Fragment} ref={setReferenceElement}>
<Button className={buttonClassNames} status="neutral" {...other}>
<Button
className={buttonClassNames}
icon={icon}
iconLayout="right"
rank="primary"
{...other}
>
{children}
<Icon
className={styles['menu__button--with-chevron']}
name={icon}
purpose="decorative"
size="1.25rem"
/>
</Button>
</HeadlessMenu.Button>
);
Expand Down
102 changes: 57 additions & 45 deletions src/components/Menu/__snapshots__/Menu-v2.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ exports[`<Menu /> Default story renders snapshot 1`] = `
aria-controls="headlessui-menu-items-:r1:"
aria-expanded="true"
aria-haspopup="menu"
class="button button--lg button--secondary button--neutral menu__button"
class="button button--layout-right button--primary button--lg button--variant-default menu__button"
data-headlessui-state="open"
id="headlessui-menu-button-:r0:"
type="button"
>
Documentation Links
<svg
aria-hidden="true"
class="icon menu__button--with-chevron"
fill="currentColor"
height="1.25rem"
style="--icon-size: 1.25rem;"
viewBox="0 0 24 24"
width="1.25rem"
xmlns="http://www.w3.org/2000/svg"
<span
class="button__text"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
Documentation Links
<svg
aria-hidden="true"
class="icon"
fill="currentColor"
height="1.5rem"
style="--icon-size: 1.5rem;"
viewBox="0 0 24 24"
width="1.5rem"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
</span>
</button>
</div>
`;
Expand Down Expand Up @@ -125,26 +129,30 @@ exports[`<Menu /> WithLongButtonText story renders snapshot 1`] = `
aria-controls="headlessui-menu-items-:r7:"
aria-expanded="true"
aria-haspopup="menu"
class="button button--lg button--secondary button--neutral menu__button"
class="button button--layout-right button--primary button--lg button--variant-default menu__button"
data-headlessui-state="open"
id="headlessui-menu-button-:r6:"
type="button"
>
Long Trigger Button Text to Demonstrate Popover Matching
<svg
aria-hidden="true"
class="icon menu__button--with-chevron"
fill="currentColor"
height="1.25rem"
style="--icon-size: 1.25rem;"
viewBox="0 0 24 24"
width="1.25rem"
xmlns="http://www.w3.org/2000/svg"
<span
class="button__text"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
Long Trigger Button Text to Demonstrate Popover Matching
<svg
aria-hidden="true"
class="icon"
fill="currentColor"
height="1.5rem"
style="--icon-size: 1.5rem;"
viewBox="0 0 24 24"
width="1.5rem"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
</span>
</button>
</div>
`;
Expand All @@ -158,26 +166,30 @@ exports[`<Menu /> WithShortButtonText story renders snapshot 1`] = `
aria-controls="headlessui-menu-items-:rd:"
aria-expanded="true"
aria-haspopup="menu"
class="button button--lg button--secondary button--neutral menu__button"
class="button button--layout-right button--primary button--lg button--variant-default menu__button"
data-headlessui-state="open"
id="headlessui-menu-button-:rc:"
type="button"
>
Menu
<svg
aria-hidden="true"
class="icon menu__button--with-chevron"
fill="currentColor"
height="1.25rem"
style="--icon-size: 1.25rem;"
viewBox="0 0 24 24"
width="1.25rem"
xmlns="http://www.w3.org/2000/svg"
<span
class="button__text"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
Menu
<svg
aria-hidden="true"
class="icon"
fill="currentColor"
height="1.5rem"
style="--icon-size: 1.5rem;"
viewBox="0 0 24 24"
width="1.5rem"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M15.88 9.29L12 13.17 8.12 9.29c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0z"
/>
</svg>
</span>
</button>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

box-shadow: var(--eds-box-shadow-md);
background-color: var(--eds-theme-color-background-utility-container);

&:focus-visible {
outline: none;
}
}

.popover-container > *[role=none] + *[role=none] {
Expand Down
5 changes: 2 additions & 3 deletions src/components/PopoverListItem/PopoverListItem-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
}
}

.popover-list-item--focused,
.popover-list-item:focus-visible {
box-shadow: 0 0 0 2px var(--eds-theme-color-border-utility-focus);
.popover-list-item--focused {
background-color: var(--eds-theme-color-background-utility-default-no-emphasis-hover);
}

.popover-list-item--disabled {
Expand Down
Loading