Skip to content
Closed
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
3 changes: 3 additions & 0 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ consider additional positioning prop support on a case-by-case basis.
- The `v8` version of `@zendeskgarden/react-dropdowns` is no longer maintained and is
renamed to `@zendeskgarden/react-dropdowns.legacy` in `v9`
- `Menu`: value `auto` is no longer valid for the `fallbackPlacements` prop.
- `Menu`: new `restoreFocus` prop (default: `true`) returns focus to trigger
after menu interaction. To keep the dropdown open on selection,
set `restoreFocus={false}` and manage focus manually.
- Removed `label` prop from `OptGroup`. Use `legend` instead.

#### @zendeskgarden/react-forms
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion packages/dropdowns/demo/stories/MenuStory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CartIcon from '@zendeskgarden/svg-icons/src/16/shopping-cart-stroke.svg';
import { Grid } from '@zendeskgarden/react-grid';
import { IMenuProps, Item, ItemGroup, Separator, Menu } from '@zendeskgarden/react-dropdowns';
import { IItem, Items } from './types';
import { Modal } from '@zendeskgarden/react-modals';

const MenuItem = ({ icon, meta, ...item }: IItem) => {
return (
Expand All @@ -27,12 +28,19 @@ interface IArgs extends IMenuProps {
}

export const MenuStory: StoryFn<IArgs> = ({ items, ...args }) => {
const [openModal, setOpenModal] = React.useState(false);

return (
<Grid>
<Grid.Row justifyContent="center" style={{ height: 800 }}>
<Grid.Col alignSelf="center" textAlign="center">
<div style={{ display: 'inline-block', position: 'relative', width: 200 }}>
<Menu {...args}>
<Menu
{...args}
onChange={changes => {
changes.value && setOpenModal(true);
}}
>
{items.map(item => {
if ('items' in item) {
return (
Expand All @@ -59,6 +67,13 @@ export const MenuStory: StoryFn<IArgs> = ({ items, ...args }) => {
</Menu>
</div>
</Grid.Col>
{openModal && (
<Modal onClose={() => setOpenModal(false)}>
<Modal.Body>
<p>Modal content</p>
</Modal.Body>
</Modal>
)}
</Grid.Row>
</Grid>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/dropdowns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@floating-ui/react-dom": "^2.0.0",
"@zendeskgarden/container-combobox": "^2.0.0",
"@zendeskgarden/container-menu": "^0.4.0",
"@zendeskgarden/container-menu": "0.5.0",
"@zendeskgarden/container-utilities": "^2.0.0",
"@zendeskgarden/react-buttons": "^9.0.0-next.26",
"@zendeskgarden/react-forms": "^9.0.0-next.26",
Expand Down
24 changes: 20 additions & 4 deletions packages/dropdowns/src/elements/menu/Menu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ describe('Menu', () => {
expect(item).toBeVisible();
});

it('applies `defaultFocusedValue`', async () => {
const { getByTestId } = render(
<TestMenu defaultExpanded defaultFocusedValue="Cactus">
it('applies `defaultFocusedValue` after a keyboard event opens the menu', async () => {
const { getByTestId, getByRole } = render(
<TestMenu defaultFocusedValue="Cactus">
<Item value="Flower" data-test-id="item-01">
Flower
<Item.Meta>Smooth</Item.Meta>
Expand All @@ -148,8 +148,22 @@ describe('Menu', () => {
);

await floating();
const trigger = getByRole('button');

// open menu with onClick
await user.click(trigger);
const item = getByTestId('item-02');
// focus remains on trigger with mouseEvents
expect(trigger).toHaveFocus();

// close menu
await user.click(trigger);
expect(item).not.toBeVisible();

// open menu with keyboard
trigger.focus();
await user.keyboard(' ');
// focus is on the focused item associated with `defaultFocusedValue`
expect(item).toHaveFocus();
});

Expand Down Expand Up @@ -603,14 +617,15 @@ describe('Menu', () => {
});

it('calls onChange as expected', async () => {
const { getByTestId } = render(
const { getByRole, getByTestId } = render(
<TestMenu isExpanded focusedValue="Cactus" onChange={handleChange}>
<Item value="Flower" data-test-id="flower" />
<Item value="Cactus" />
</TestMenu>
);

await floating();
const trigger = getByRole('button');
const item1 = getByTestId('flower');

await act(async () => {
Expand All @@ -620,6 +635,7 @@ describe('Menu', () => {
const changeTypes = handleChange.mock.calls.map(([change]) => change.type);

expect(changeTypes).toMatchObject(['menuItem:mouseMove', 'menuItem:click']);
expect(trigger).toHaveFocus();
});

it('handles `focusedValue` and `isExpanded` as expected', async () => {
Expand Down