-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Implement onPositioningEnd callback #30177
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
Merged
ling1726
merged 7 commits into
microsoft:master
from
ling1726:react-positioning/feat/on-positioning-end
Jan 9, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dc5c459
feat: Implement onPositioningEnd callback
ling1726 57929ba
changefile
ling1726 133a707
fix vr test
ling1726 e2cf689
revert
ling1726 566bd16
update doc
ling1726 8fc8bc0
update doc
ling1726 b664e78
merge conflict
ling1726 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-positioning-d30b18b7-e743-42d7-b3bc-0b1ff22655fd.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: Implement onPositioningEnd callback", | ||
| "packageName": "@fluentui/react-positioning", | ||
| "email": "lingfangao@hotmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
127 changes: 127 additions & 0 deletions
127
...ents/react-components/stories/Concepts/Positioning/PositioningListenToUpdates.stories.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,127 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| useId, | ||
| Text, | ||
| makeStyles, | ||
| shorthands, | ||
| tokens, | ||
| Popover, | ||
| Button, | ||
| PopoverTrigger, | ||
| PopoverSurface, | ||
| PositioningImperativeRef, | ||
| PopoverProps, | ||
| } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| root: { | ||
| display: 'flex', | ||
| ...shorthands.gap('20px'), | ||
| }, | ||
|
|
||
| button: { | ||
| display: 'block', | ||
| minWidth: '120px', | ||
| }, | ||
|
|
||
| logContainer: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| }, | ||
|
|
||
| logLabel: { | ||
| color: tokens.colorNeutralForegroundOnBrand, | ||
| backgroundColor: tokens.colorBrandBackground, | ||
| width: 'fit-content', | ||
| fontWeight: tokens.fontWeightBold, | ||
| ...shorthands.padding('2px', '12px'), | ||
| }, | ||
|
|
||
| log: { | ||
| overflowY: 'auto', | ||
| boxShadow: tokens.shadow16, | ||
| position: 'relative', | ||
| minWidth: '200px', | ||
| height: '200px', | ||
| ...shorthands.border('2px', 'solid', tokens.colorBrandBackground), | ||
| ...shorthands.padding('12px', '12px'), | ||
| }, | ||
| }); | ||
|
|
||
| export const ListenToUpdates = () => { | ||
| const styles = useStyles(); | ||
| const labelId = useId(); | ||
| const [statusLog, setStatusLog] = React.useState<number[]>([]); | ||
| const positioningRef = React.useRef<PositioningImperativeRef>(null); | ||
| const [open, setOpen] = React.useState(false); | ||
|
|
||
| const onOpenChange: PopoverProps['onOpenChange'] = React.useCallback((e, data) => { | ||
| setOpen(data.open); | ||
| if (!data.open) { | ||
| setStatusLog([]); | ||
| } | ||
| }, []); | ||
|
|
||
| const updatePosition = React.useCallback(() => { | ||
| positioningRef.current?.updatePosition(); | ||
| }, []); | ||
|
|
||
| const onPositioningEnd = React.useCallback(() => { | ||
| setStatusLog(s => [Date.now(), ...s]); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div className={styles.root}> | ||
| <div> | ||
| <Popover | ||
| open={open} | ||
| onOpenChange={onOpenChange} | ||
| positioning={{ positioningRef, onPositioningEnd, position: 'below' }} | ||
| > | ||
| <PopoverTrigger> | ||
| <Button className={styles.button}>Open popover</Button> | ||
| </PopoverTrigger> | ||
| <PopoverSurface> | ||
| <Button className={styles.button} onClick={updatePosition}> | ||
| Update position | ||
| </Button> | ||
| </PopoverSurface> | ||
| </Popover> | ||
| </div> | ||
| <div className={styles.logContainer}> | ||
| <div className={styles.logLabel} id={labelId}> | ||
| Status log | ||
| </div> | ||
| <div role="log" aria-labelledby={labelId} className={styles.log}> | ||
| {statusLog.map((time, i) => { | ||
| const date = new Date(time); | ||
| return ( | ||
| <div key={i}> | ||
| {date.toLocaleTimeString()} <Text weight="bold">Position updated [{i}]</Text> | ||
| </div> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ListenToUpdates.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: [ | ||
| 'Positioning happens outside of the React render lifecycle for performance purposes so that a position update', | ||
| 'does not need to:', | ||
| '- trigger by a re-render', | ||
| '- be dependent on a re-render', | ||
| '', | ||
| 'This constraint makes it difficult to know exactly when an element has been positioned. In order to listen', | ||
| 'to position updates you can use the `onPositioningEnd` callback.', | ||
| '', | ||
| '> ⚠️ _Very few use cases would actually require listening to position updates. Please remember that_', | ||
| '_there is a difference between this and the **open/close state** which is normally handled in React_', | ||
| ].join('\n'), | ||
| }, | ||
| }, | ||
| }; |
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
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
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
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.