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

Enabling hide middleware in DropdownMenu by default #2233

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

r100-stack
Copy link
Member

@r100-stack r100-stack commented Sep 11, 2024

Changes

Fixes #2235.

This PR makes DropdownMenu expose the middleware prop. The hide middleware is enabled by default and can be opted out from. (#2233 (comment)).

Only the hide middleware is modifiable for now. This keeps the API surface small, manageable, and less buggy. As and when we need to expose more middleware, we can do so in the future.

Unrelated fixes:

  • Fixed the hide middleware in Popover to actually apply visibility: hidden. Up till now, that middleware used to unintentionally be no-op. (sandbox)
  • Fixed merging interactions logic in Popover.
    • e.g. suppose we want to enable foobar by default. Doing {foo: true, ...userProps} actually results in {foobar: undefined} if userProps.foobar = undefined. The fix I used was {foobar: userProps.foobar ?? true}.

Testing

Added e2e test and story.

@mayank99 pointed out some issues that we faced with the hide modifier in old versions of itwinui-react that used to use popper instead of floating-ui. I made sure that the previous issues no longer happen after this PR or are no longer related to this PR:

Docs

Added changesets and docs.

@r100-stack r100-stack changed the title Enabling hide middleware in DropdownMenu Exposing middleware.hide prop in DropdownMenu Sep 19, 2024
@r100-stack r100-stack marked this pull request as ready for review September 19, 2024 16:25
@r100-stack r100-stack requested a review from a team as a code owner September 19, 2024 16:25
@r100-stack r100-stack requested review from mayank99 and smmr-dn and removed request for a team September 19, 2024 16:25
@r100-stack r100-stack changed the title Exposing middleware.hide prop in DropdownMenu Enabling hide middleware in DropdownMenu by default Sep 19, 2024
apps/website/src/content/docs/dropdownmenu.mdx Outdated Show resolved Hide resolved
.changeset/slimy-vans-lick.md Outdated Show resolved Hide resolved
apps/react-workshop/src/DropdownMenu.stories.tsx Outdated Show resolved Hide resolved
* @see https://floating-ui.com/docs/middleware
*/
middleware?: {
hide?: boolean;
Copy link
Contributor

@mayank99 mayank99 Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building upon #2233 (comment), I think middleware.hide should be exposed in all places that use usePopover (directly or indirectly).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be under dropdownMenuProps in ComboBox and under popoverProps in Select.

} from '@itwin/itwinui-react';
import { useSearchParams } from '@remix-run/react';
import { SvgMore } from 'node_modules/@itwin/itwinui-react/esm/utils/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not rely on these internal paths; instead import from @itwin/itwinui-icons-react if you need this icon.

@@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
Copy link
Contributor

@smmr-dn smmr-dn Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is waitFor being used in this unit test? I think it might be a stray import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with dropdown menu when the dropdown trigger is scrolled out of the view
3 participants