-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-headless-components-preview): add headless MenuButton #36320
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
Open
mainframev
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
mainframev:feat/headless-menu-button
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a064fa
feat(react-button): add useMenuButtonBase_unstable for headless MenuB…
mainframev 13e104d
docs: add headless Menu stories
mainframev 484bda8
Potential fix for pull request finding
mainframev bbae420
fixup! feat(react-button): add useMenuButtonBase_unstable for headles…
mainframev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-button-3e45fb7a-a8fa-4902-a694-fa9b89a68fd1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat: add useMenuButtonBase hook", | ||
| "packageName": "@fluentui/react-button", | ||
| "email": "vgenaev@gmail.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-headless-components-preview-7246c651-b258-4694-b0e7-45b666b15aae.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "feat: add headless MenuButton", | ||
| "packageName": "@fluentui/react-headless-components-preview", | ||
| "email": "vgenaev@gmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
packages/react-components/react-button/library/src/MenuButton.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| export type { MenuButtonProps, MenuButtonSlots, MenuButtonState } from './components/MenuButton/index'; | ||
| export type { | ||
| MenuButtonBaseProps, | ||
| MenuButtonBaseState, | ||
| MenuButtonProps, | ||
| MenuButtonSlots, | ||
| MenuButtonState, | ||
| } from './components/MenuButton/index'; | ||
| export { | ||
| MenuButton, | ||
| menuButtonClassNames, | ||
| renderMenuButton_unstable, | ||
| useMenuButtonStyles_unstable, | ||
| useMenuButton_unstable, | ||
| useMenuButtonBase_unstable, | ||
| } from './components/MenuButton/index'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
packages/react-components/react-button/library/src/components/MenuButton/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| export type { MenuButtonProps, MenuButtonSlots, MenuButtonState } from './MenuButton.types'; | ||
| export type { | ||
| MenuButtonBaseProps, | ||
| MenuButtonBaseState, | ||
| MenuButtonProps, | ||
| MenuButtonSlots, | ||
| MenuButtonState, | ||
| } from './MenuButton.types'; | ||
| export { MenuButton } from './MenuButton'; | ||
| export { renderMenuButton_unstable } from './renderMenuButton'; | ||
| export { useMenuButton_unstable } from './useMenuButton'; | ||
| export { useMenuButton_unstable, useMenuButtonBase_unstable } from './useMenuButton'; | ||
| export { menuButtonClassNames, useMenuButtonStyles_unstable } from './useMenuButtonStyles.styles'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...eact-components/react-button/library/src/components/MenuButton/useMenuButtonBase.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import * as React from 'react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import '@testing-library/jest-dom'; | ||
| import { useMenuButtonBase_unstable } from './useMenuButton'; | ||
|
|
||
| describe('useMenuButtonBase_unstable', () => { | ||
| it('returns a menuIcon slot by default', () => { | ||
| const { result } = renderHook(() => useMenuButtonBase_unstable({}, React.createRef())); | ||
| expect(result.current.menuIcon).toBeDefined(); | ||
| }); | ||
|
|
||
| it('forces aria-expanded to a boolean on root', () => { | ||
| const { result } = renderHook(() => useMenuButtonBase_unstable({ 'aria-expanded': 'true' }, React.createRef())); | ||
| expect(result.current.root['aria-expanded']).toBe(true); | ||
| }); | ||
|
|
||
| it('does not include appearance/size/shape styling props', () => { | ||
| const { result } = renderHook(() => useMenuButtonBase_unstable({}, React.createRef())); | ||
| expect(result.current).not.toHaveProperty('appearance'); | ||
| expect(result.current).not.toHaveProperty('size'); | ||
| expect(result.current).not.toHaveProperty('shape'); | ||
| }); | ||
|
|
||
| it('sets iconOnly true when there are no children', () => { | ||
| const { result } = renderHook(() => useMenuButtonBase_unstable({}, React.createRef())); | ||
| expect(result.current.iconOnly).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...act-components/react-headless-components-preview/library/etc/menu-button.api.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ## API Report File for "@fluentui/react-headless-components-preview" | ||
|
|
||
| > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
|
||
| ```ts | ||
|
|
||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import type { MenuButtonBaseState } from '@fluentui/react-button'; | ||
| import { MenuButtonBaseProps as MenuButtonProps } from '@fluentui/react-button'; | ||
| import { MenuButtonSlots } from '@fluentui/react-button'; | ||
| import type * as React_2 from 'react'; | ||
| import { renderMenuButton_unstable as renderMenuButton } from '@fluentui/react-button'; | ||
|
|
||
| // @public | ||
| export const MenuButton: ForwardRefComponent<MenuButtonProps>; | ||
|
|
||
| export { MenuButtonProps } | ||
|
|
||
| export { MenuButtonSlots } | ||
|
|
||
| // @public | ||
| export type MenuButtonState = MenuButtonBaseState & { | ||
| root: { | ||
| 'data-disabled'?: string; | ||
| 'data-disabled-focusable'?: string; | ||
| 'data-icon-only'?: string; | ||
| }; | ||
| }; | ||
|
|
||
| export { renderMenuButton } | ||
|
|
||
| // @public | ||
| export const useMenuButton: (props: MenuButtonProps, ref: React_2.Ref<HTMLButtonElement | HTMLAnchorElement>) => MenuButtonState; | ||
|
|
||
| // (No @packageDocumentation comment for this package) | ||
|
|
||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...s/react-headless-components-preview/library/src/components/MenuButton/MenuButton.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
| import { MenuButton } from './MenuButton'; | ||
|
|
||
| describe('MenuButton', () => { | ||
| isConformant({ | ||
| Component: MenuButton, | ||
| displayName: 'MenuButton', | ||
| }); | ||
|
|
||
| it('renders a default state with the chevron menu icon', () => { | ||
| const result = render(<MenuButton>Open menu</MenuButton>); | ||
| const button = result.getByRole('button', { name: 'Open menu' }); | ||
| expect(button).toBeInTheDocument(); | ||
| expect(button).toHaveAttribute('type', 'button'); | ||
| expect(button).toHaveAttribute('aria-expanded', 'false'); | ||
| expect(button.querySelector('svg')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('reflects aria-expanded as a boolean', () => { | ||
| const result = render(<MenuButton aria-expanded>Open menu</MenuButton>); | ||
| const button = result.getByRole('button', { name: 'Open menu' }); | ||
| expect(button).toHaveAttribute('aria-expanded', 'true'); | ||
| }); | ||
|
|
||
| it('renders a custom menuIcon slot', () => { | ||
| const result = render(<MenuButton menuIcon={<span data-testid="custom-icon" />}>Open menu</MenuButton>); | ||
| expect(result.getByTestId('custom-icon')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders with state data attributes', () => { | ||
| const result = render( | ||
| <MenuButton disabled disabledFocusable> | ||
| Disabled | ||
| </MenuButton>, | ||
| ); | ||
| const button = result.getByRole('button', { name: 'Disabled' }); | ||
| expect(button).toHaveAttribute('data-disabled'); | ||
| expect(button).toHaveAttribute('data-disabled-focusable'); | ||
| }); | ||
|
|
||
| it('renders icon-only with the data-icon-only attribute', () => { | ||
| const result = render(<MenuButton icon={<span>Icon</span>} aria-label="Icon menu" />); | ||
| const button = result.getByRole('button', { name: 'Icon menu' }); | ||
| expect(button).toHaveAttribute('data-icon-only'); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
...onents/react-headless-components-preview/library/src/components/MenuButton/MenuButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| 'use client'; | ||
|
|
||
| import * as React from 'react'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import type { MenuButtonProps } from './MenuButton.types'; | ||
| import { useMenuButton } from './useMenuButton'; | ||
| import { renderMenuButton } from './renderMenuButton'; | ||
|
|
||
| /** | ||
| * A button that opens a menu, indicated by a chevron icon. | ||
| */ | ||
| export const MenuButton: ForwardRefComponent<MenuButtonProps> = React.forwardRef((props, ref) => { | ||
| const state = useMenuButton(props, ref); | ||
|
|
||
| return renderMenuButton(state); | ||
| }); | ||
|
|
||
| MenuButton.displayName = 'MenuButton'; |
25 changes: 25 additions & 0 deletions
25
...s/react-headless-components-preview/library/src/components/MenuButton/MenuButton.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { MenuButtonBaseState } from '@fluentui/react-button'; | ||
|
|
||
| export type { MenuButtonBaseProps as MenuButtonProps, MenuButtonSlots } from '@fluentui/react-button'; | ||
|
|
||
| /** | ||
| * MenuButton component state | ||
| */ | ||
| export type MenuButtonState = MenuButtonBaseState & { | ||
| root: { | ||
| /** | ||
| * Data attribute set when the button is disabled. | ||
| */ | ||
| 'data-disabled'?: string; | ||
|
|
||
| /** | ||
| * Data attribute set when the button is disabled but still focusable. | ||
| */ | ||
| 'data-disabled-focusable'?: string; | ||
|
|
||
| /** | ||
| * Data attribute set when the button renders only an icon. | ||
| */ | ||
| 'data-icon-only'?: string; | ||
| }; | ||
| }; |
4 changes: 4 additions & 0 deletions
4
...t-components/react-headless-components-preview/library/src/components/MenuButton/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export { MenuButton } from './MenuButton'; | ||
| export { renderMenuButton } from './renderMenuButton'; | ||
| export { useMenuButton } from './useMenuButton'; | ||
| export type { MenuButtonSlots, MenuButtonProps, MenuButtonState } from './MenuButton.types'; |
1 change: 1 addition & 0 deletions
1
...s/react-headless-components-preview/library/src/components/MenuButton/renderMenuButton.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { renderMenuButton_unstable as renderMenuButton } from '@fluentui/react-button'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Avatar Converged 1 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/ProgressBar converged 3 screenshots
vr-tests-react-components/Skeleton converged 1 screenshots
vr-tests-react-components/TagPicker 1 screenshots
There were 1 duplicate changes discarded. Check the build logs for more information.