-
Notifications
You must be signed in to change notification settings - Fork 2.9k
React overflow/feature/refactor internals #36255
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
bsunderhus
wants to merge
14
commits into
microsoft:master
Choose a base branch
from
bsunderhus:react-overflow/feature/refactor-internals
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5f83b8b
docs
bsunderhus 8040502
tmp skip
bsunderhus 04da9a0
refactor: stabilize overflow manager lifecycle
bsunderhus ad40a62
refactor overflow lifecycle boundaries
bsunderhus 5b89535
refine react-overflow bridge subscriptions
bsunderhus 7744e75
finalize overflow docs
bsunderhus 0fc644d
simplify overflow container observation
bsunderhus 94e7a92
include paint probing to ensure a single paint correctness
bsunderhus 36b5ff2
chore: remove manager state from Overflow container
bsunderhus 827911a
rename to useSyncOverflowSnapshot
bsunderhus 052cd84
chore: revert breaking changes in the API
bsunderhus 6656199
chore(react-overflow): avoid API breaking changes + cleanup of the re…
bsunderhus df587aa
force update to avoid splitting tasks
bsunderhus efff15f
test(priority-overflow): update overflowManager tests to match new sn…
bsunderhus 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
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
147 changes: 147 additions & 0 deletions
147
packages/react-components/priority-overflow/src/overflowManager.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,147 @@ | ||
| import { createOverflowManager } from './overflowManager'; | ||
| import type { ObserveOptions } from './types'; | ||
|
|
||
| describe('overflowManager', () => { | ||
| beforeAll(() => { | ||
| global.ResizeObserver = class ResizeObserver { | ||
| public observe() { | ||
| // do nothing | ||
| } | ||
|
|
||
| public unobserve() { | ||
| // do nothing | ||
| } | ||
|
|
||
| public disconnect() { | ||
| // do nothing | ||
| } | ||
| } as unknown as typeof ResizeObserver; | ||
| }); | ||
|
|
||
| const createElementWithSize = (tagName: string, width: number) => { | ||
| const element = document.createElement(tagName); | ||
| Object.defineProperty(element, 'offsetWidth', { configurable: true, value: width }); | ||
| Object.defineProperty(element, 'offsetHeight', { configurable: true, value: width }); | ||
|
|
||
| return element; | ||
| }; | ||
|
|
||
| const createContainer = (width: number) => { | ||
| const container = document.createElement('div'); | ||
| Object.defineProperty(container, 'clientWidth', { configurable: true, value: width }); | ||
| Object.defineProperty(container, 'clientHeight', { configurable: true, value: width }); | ||
|
|
||
| return container; | ||
| }; | ||
|
|
||
| const createObserveOptions = (options: Partial<ObserveOptions> = {}): ObserveOptions => ({ | ||
| overflowAxis: 'horizontal', | ||
| overflowDirection: 'end', | ||
| padding: 10, | ||
| minimumVisible: 0, | ||
| hasHiddenItems: false, | ||
| onUpdateItemVisibility: jest.fn(), | ||
| onUpdateOverflow: jest.fn(), | ||
| ...options, | ||
| }); | ||
|
|
||
| const getVisibleIds = (manager: ReturnType<typeof createOverflowManager>) => | ||
| manager | ||
| .getSnapshot() | ||
| .visibleItems.map(item => item.id) | ||
| .sort(); | ||
|
|
||
| const getInvisibleIds = (manager: ReturnType<typeof createOverflowManager>) => | ||
| manager | ||
| .getSnapshot() | ||
| .invisibleItems.map(item => item.id) | ||
| .sort(); | ||
|
|
||
| it('should expose a stable snapshot after forceUpdate', () => { | ||
| const manager = createOverflowManager(); | ||
| const container = createContainer(100); | ||
| const itemA = createElementWithSize('button', 40); | ||
| const itemB = createElementWithSize('button', 40); | ||
| const menu = createElementWithSize('button', 20); | ||
|
|
||
| manager.setOptions(createObserveOptions()); | ||
| manager.addItem({ element: itemA, id: 'a', priority: 1 }); | ||
| manager.addItem({ element: itemB, id: 'b', priority: 0 }); | ||
| manager.addOverflowMenu(menu); | ||
| manager.observe(container); | ||
| manager.forceUpdate(); | ||
|
|
||
| expect(getVisibleIds(manager)).toEqual(['a', 'b']); | ||
| expect(getInvisibleIds(manager)).toEqual([]); | ||
| expect(manager.getSnapshot().groupVisibility).toEqual({}); | ||
| }); | ||
|
|
||
| it('should update snapshot and notify subscribers when options change', () => { | ||
| const manager = createOverflowManager(); | ||
| const container = createContainer(100); | ||
| const itemA = createElementWithSize('button', 40); | ||
| const itemB = createElementWithSize('button', 40); | ||
| const menu = createElementWithSize('button', 20); | ||
| const listener = jest.fn(); | ||
|
|
||
| manager.setOptions(createObserveOptions()); | ||
| manager.addItem({ element: itemA, id: 'a', priority: 1 }); | ||
| manager.addItem({ element: itemB, id: 'b', priority: 0 }); | ||
| manager.addOverflowMenu(menu); | ||
| manager.observe(container); | ||
| manager.forceUpdate(); | ||
| const unsubscribe = manager.subscribe(listener); | ||
|
|
||
| manager.setOptions({ padding: 30 }); | ||
|
|
||
| expect(listener).toHaveBeenCalled(); | ||
| expect(getVisibleIds(manager)).toEqual(['a']); | ||
| expect(getInvisibleIds(manager)).toEqual(['b']); | ||
| expect(manager.getSnapshot().groupVisibility).toEqual({}); | ||
|
|
||
| unsubscribe(); | ||
| }); | ||
|
|
||
| it('should reset snapshot state when observation cleanup runs', () => { | ||
| const manager = createOverflowManager(); | ||
| const container = createContainer(100); | ||
| const item = createElementWithSize('button', 40); | ||
|
|
||
| manager.setOptions(createObserveOptions()); | ||
| manager.addItem({ element: item, id: 'a', priority: 1 }); | ||
| const cleanup = manager.observe(container); | ||
| manager.forceUpdate(); | ||
|
|
||
| expect(getVisibleIds(manager)).toEqual(['a']); | ||
|
|
||
| cleanup(); | ||
|
|
||
| expect(manager.getSnapshot()).toEqual({ | ||
| visibleItems: [], | ||
| invisibleItems: [], | ||
| groupVisibility: {}, | ||
| }); | ||
| }); | ||
|
|
||
| it('should remove items through removeItem', () => { | ||
| const manager = createOverflowManager(); | ||
| const container = createContainer(100); | ||
| const item = createElementWithSize('button', 40); | ||
|
|
||
| manager.setOptions(createObserveOptions()); | ||
| manager.addItem({ element: item, id: 'a', priority: 1 }); | ||
| manager.observe(container); | ||
| manager.forceUpdate(); | ||
|
|
||
| expect(getVisibleIds(manager)).toEqual(['a']); | ||
|
|
||
| manager.removeItem('a'); | ||
| manager.forceUpdate(); | ||
|
|
||
| expect(manager.getSnapshot()).toEqual({ | ||
| visibleItems: [], | ||
| invisibleItems: [], | ||
| groupVisibility: {}, | ||
| }); | ||
| }); | ||
| }); |
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/Charts-DonutChart 3 screenshots
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 2 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/ProgressBar converged 3 screenshots
vr-tests-react-components/TagPicker 2 screenshots
There were 2 duplicate changes discarded. Check the build logs for more information.