-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-tree): export useTreeItemPersonaLayoutContextValues_unstable and TreeItemPersonaLayoutContextValues #36057
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
Draft
dmytrokirpa
wants to merge
2
commits into
microsoft:master
Choose a base branch
from
dmytrokirpa:feat/tree-base-hooks
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.
Draft
Changes from all commits
Commits
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
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
change/@fluentui-react-tree-bbd9207d-d370-4635-b213-bbe2b2d53a24.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,8 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Export useTreeItemPersonaLayoutContextValues_unstable and TreeItemPersonaLayoutContextValues from @fluentui/react-tree", | ||
| "packageName": "@fluentui/react-tree", | ||
| "email": "dmytrokirpa@microsoft.com", | ||
| "dependentChangeType": "patch", | ||
| "date": "2026-04-26T20:21:03.202Z" | ||
| } | ||
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
84 changes: 84 additions & 0 deletions
84
packages/react-components/react-tree/library/src/components/FlatTree/useFlatTree.test.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,84 @@ | ||
| import * as React from 'react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useFlatTree_unstable } from './useFlatTree'; | ||
| import { useFlatTreeContextValues_unstable } from './useFlatTreeContextValues'; | ||
|
|
||
| describe('useFlatTree_unstable', () => { | ||
| let ref: React.RefObject<HTMLElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLElement>(); | ||
| }); | ||
|
|
||
| it('returns default state with div root element', () => { | ||
| const { result } = renderHook(() => useFlatTree_unstable({}, ref)); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| components: { root: 'div' }, | ||
| contextType: 'root', | ||
| level: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects size prop in state', () => { | ||
| const { result } = renderHook(() => useFlatTree_unstable({ size: 'small' }, ref)); | ||
|
|
||
| expect(result.current.size).toBe('small'); | ||
| }); | ||
|
|
||
| it('reflects appearance prop in state', () => { | ||
| const { result } = renderHook(() => useFlatTree_unstable({ appearance: 'subtle' }, ref)); | ||
|
|
||
| expect(result.current.appearance).toBe('subtle'); | ||
| }); | ||
|
|
||
| it('reflects selectionMode prop in state', () => { | ||
| const { result } = renderHook(() => useFlatTree_unstable({ selectionMode: 'multiselect' }, ref)); | ||
|
|
||
| expect(result.current.selectionMode).toBe('multiselect'); | ||
| }); | ||
|
|
||
| it('defaults navigationMode to tree', () => { | ||
| const { result } = renderHook(() => useFlatTree_unstable({}, ref)); | ||
|
|
||
| expect(result.current.navigationMode).toBe('tree'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useFlatTreeContextValues_unstable', () => { | ||
| let ref: React.RefObject<HTMLElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLElement>(); | ||
| }); | ||
|
|
||
| it('returns tree context with root contextType', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useFlatTree_unstable({}, ref); | ||
| return useFlatTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree).toMatchObject({ | ||
| contextType: 'root', | ||
| level: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects selectionMode in tree context', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useFlatTree_unstable({ selectionMode: 'single' }, ref); | ||
| return useFlatTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree.selectionMode).toBe('single'); | ||
| }); | ||
|
|
||
| it('reflects size in tree context', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useFlatTree_unstable({ size: 'small' }, ref); | ||
| return useFlatTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree.size).toBe('small'); | ||
| }); | ||
| }); |
90 changes: 90 additions & 0 deletions
90
packages/react-components/react-tree/library/src/components/Tree/useTree.test.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,90 @@ | ||
| import * as React from 'react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useTree_unstable } from './useTree'; | ||
| import { useTreeContextValues_unstable } from './useTreeContextValues'; | ||
|
|
||
| describe('useTree_unstable', () => { | ||
| let ref: React.RefObject<HTMLElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLElement>(); | ||
| }); | ||
|
|
||
| it('returns default state with div root element', () => { | ||
| const { result } = renderHook(() => useTree_unstable({}, ref)); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| components: { root: 'div' }, | ||
| contextType: 'root', | ||
| level: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects size prop in state', () => { | ||
| const { result } = renderHook(() => useTree_unstable({ size: 'small' }, ref)); | ||
|
|
||
| expect(result.current.size).toBe('small'); | ||
| }); | ||
|
|
||
| it('reflects appearance prop in state', () => { | ||
| const { result } = renderHook(() => useTree_unstable({ appearance: 'subtle-alpha' }, ref)); | ||
|
|
||
| expect(result.current.appearance).toBe('subtle-alpha'); | ||
| }); | ||
|
|
||
| it('reflects selectionMode prop in state', () => { | ||
| const { result } = renderHook(() => useTree_unstable({ selectionMode: 'multiselect' }, ref)); | ||
|
|
||
| expect(result.current.selectionMode).toBe('multiselect'); | ||
| }); | ||
|
|
||
| it('defaults navigationMode to tree', () => { | ||
| const { result } = renderHook(() => useTree_unstable({}, ref)); | ||
|
|
||
| expect(result.current.navigationMode).toBe('tree'); | ||
| }); | ||
|
|
||
| it('reflects navigationMode prop in state', () => { | ||
| const { result } = renderHook(() => useTree_unstable({ navigationMode: 'treegrid' }, ref)); | ||
|
|
||
| expect(result.current.navigationMode).toBe('treegrid'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useTreeContextValues_unstable', () => { | ||
| let ref: React.RefObject<HTMLElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLElement>(); | ||
| }); | ||
|
|
||
| it('returns tree context with root contextType', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useTree_unstable({}, ref); | ||
| return useTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree).toMatchObject({ | ||
| contextType: 'root', | ||
| level: 1, | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects selectionMode in tree context', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useTree_unstable({ selectionMode: 'single' }, ref); | ||
| return useTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree.selectionMode).toBe('single'); | ||
| }); | ||
|
|
||
| it('reflects appearance in tree context', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useTree_unstable({ appearance: 'transparent' }, ref); | ||
| return useTreeContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.tree.appearance).toBe('transparent'); | ||
| }); | ||
| }); |
69 changes: 69 additions & 0 deletions
69
packages/react-components/react-tree/library/src/components/TreeItem/useTreeItem.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,69 @@ | ||
| import * as React from 'react'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
| import { useTreeItem_unstable } from './useTreeItem'; | ||
| import { useTreeItemContextValues_unstable } from './useTreeItemContextValues'; | ||
|
|
||
| describe('useTreeItem_unstable', () => { | ||
| let ref: React.RefObject<HTMLDivElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLDivElement>(); | ||
| }); | ||
|
|
||
| it('returns default state with div root element', () => { | ||
| const { result } = renderHook(() => useTreeItem_unstable({ value: 'item-1', itemType: 'leaf' }, ref)); | ||
|
|
||
| expect(result.current).toMatchObject({ | ||
| components: { root: 'div' }, | ||
| itemType: 'leaf', | ||
| value: 'item-1', | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects branch itemType in state', () => { | ||
| const { result } = renderHook(() => useTreeItem_unstable({ value: 'item-1', itemType: 'branch' }, ref)); | ||
|
|
||
| expect(result.current.itemType).toBe('branch'); | ||
| }); | ||
|
|
||
| it('reflects value prop in state', () => { | ||
| const { result } = renderHook(() => useTreeItem_unstable({ value: 'custom-value', itemType: 'leaf' }, ref)); | ||
|
|
||
| expect(result.current.value).toBe('custom-value'); | ||
| }); | ||
|
|
||
| it('defaults open to false for leaf items', () => { | ||
| const { result } = renderHook(() => useTreeItem_unstable({ value: 'item-1', itemType: 'leaf' }, ref)); | ||
|
|
||
| expect(result.current.open).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('useTreeItemContextValues_unstable', () => { | ||
| let ref: React.RefObject<HTMLDivElement | null>; | ||
|
|
||
| beforeEach(() => { | ||
| ref = React.createRef<HTMLDivElement>(); | ||
| }); | ||
|
|
||
| it('returns treeItem context with value and itemType', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useTreeItem_unstable({ value: 'item-1', itemType: 'leaf' }, ref); | ||
| return useTreeItemContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.treeItem).toMatchObject({ | ||
| value: 'item-1', | ||
| itemType: 'leaf', | ||
| }); | ||
| }); | ||
|
|
||
| it('reflects open state in treeItem context', () => { | ||
| const { result } = renderHook(() => { | ||
| const state = useTreeItem_unstable({ value: 'item-1', itemType: 'branch', open: true }, ref); | ||
| return useTreeItemContextValues_unstable(state); | ||
| }); | ||
|
|
||
| expect(result.current.treeItem.open).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
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.
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/CalendarCompat 4 screenshots
vr-tests-react-components/Charts-DonutChart 1 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/ProgressBar converged 3 screenshots
There were 1 duplicate changes discarded. Check the build logs for more information.