This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
fix(Chat): positiong fixes for actions #2300
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b8cc94
fix(Chat): positiong fixes for actions
layershifter e9e685f
add changelog entry
layershifter 681a18f
Merge branches 'fix/chat-actions' and 'master' of https://github.com/…
layershifter 2e3d1d3
update screener steps
layershifter b9f6127
revert change, add comment
layershifter 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
16 changes: 16 additions & 0 deletions
16
docs/src/examples/components/Chat/Content/ChatExampleActions.shorthand.steps.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,16 @@ | ||
| import { ChatMessage } from '@fluentui/react' | ||
|
|
||
| const selectors = { | ||
| message: `.${ChatMessage.className}`, | ||
| } | ||
|
|
||
| const config: ScreenerTestsConfig = { | ||
| themes: ['teams', 'teamsDark', 'teamsHighContrast'], | ||
| steps: [ | ||
| builder => builder.hover(selectors.message).snapshot('Hovers the first message'), | ||
| builder => builder.click(selectors.message).snapshot('Focus the first message via mouse click'), | ||
| (builder, keys) => builder.keys('body', keys.tab).snapshot('Focuses a message via keyboard'), | ||
| ], | ||
| } | ||
|
|
||
| export default config |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,30 @@ | ||
| import * as React from 'react' | ||
| import { Ref, isRefObject } from '@fluentui/react-component-ref' | ||
| import * as _ from 'lodash' | ||
| import PopperJS, * as _PopperJS from 'popper.js' | ||
| import { Ref, isRefObject } from '@fluentui/react-component-ref' | ||
| import * as React from 'react' | ||
|
|
||
| import { getPlacement, applyRtlToOffset } from './positioningHelper' | ||
| import { PopperProps, PopperChildrenFn } from './types' | ||
| import getScrollParent from './getScrollParent' | ||
| import { getPlacement, applyRtlToOffset } from './positioningHelper' | ||
| import { PopperProps } from './types' | ||
|
|
||
| /** | ||
| * Memoize a result using deep equality. This hook has two advantages over | ||
| * React.useMemo: it uses deep equality to compare memo keys, and it guarantees | ||
| * that the memo function will only be called if the keys are unequal. | ||
| * React.useMemo cannot be relied on to do this, since it is only a performance | ||
| * optimization (see https://reactjs.org/docs/hooks-reference.html#usememo). | ||
| * | ||
| * Copied from https://github.com/apollographql/react-apollo/blob/master/packages/hooks/src/utils/useDeepMemo.ts. | ||
| */ | ||
| function useDeepMemo<TKey, TValue>(memoFn: () => TValue, key: TKey): TValue { | ||
| const ref = React.useRef<{ key: TKey; value: TValue }>() | ||
|
|
||
| if (!ref.current || !_.isEqual(key, ref.current.key)) { | ||
| ref.current = { key, value: memoFn() } | ||
| } | ||
|
|
||
| return ref.current.value | ||
| } | ||
|
|
||
| // `popper.js` has a UMD build without `.default`, it breaks CJS builds: | ||
| // https://github.com/rollup/rollup/issues/1267#issuecomment-446681320 | ||
|
|
@@ -35,6 +54,7 @@ const createPopper = ( | |
|
|
||
| return instance | ||
| } | ||
|
|
||
| /** | ||
| * Popper relies on the 3rd party library [Popper.js](https://github.com/FezVrasta/popper.js) for positioning. | ||
| */ | ||
|
|
@@ -58,18 +78,61 @@ const Popper: React.FunctionComponent<PopperProps> = props => { | |
|
|
||
| const popperRef = React.useRef<PopperJS>() | ||
| const contentRef = React.useRef<HTMLElement>(null) | ||
|
|
||
| const latestPlacement = React.useRef<PopperJS.Placement>(proposedPlacement) | ||
| const [computedPlacement, setComputedPlacement] = React.useState<PopperJS.Placement>( | ||
| proposedPlacement, | ||
| ) | ||
|
|
||
| const computedModifiers: PopperJS.Modifiers = React.useMemo( | ||
| const hasScrollableElement = React.useMemo(() => { | ||
| const scrollParentElement = getScrollParent(contentRef.current) | ||
|
|
||
| return scrollParentElement !== scrollParentElement.ownerDocument.body | ||
| }, [contentRef]) | ||
| // Is a broken dependency and can cause potential bugs, we should rethink this as all other refs | ||
| // in this component. | ||
|
|
||
| const computedModifiers: PopperJS.Modifiers = useDeepMemo( | ||
| () => | ||
| offset && { | ||
| offset: { offset: rtl ? applyRtlToOffset(offset, position) : offset }, | ||
| keepTogether: { enabled: false }, | ||
| }, | ||
| [rtl, offset, position], | ||
| _.merge( | ||
| /** | ||
| * This prevents blurrines in chrome, when the coordinates are odd numbers alternative | ||
| * would be to use `fn` and manipulate the computed style or ask popper to fix it but | ||
| * since there is presumably only handful of poppers displayed on the page, the | ||
| * performance impact should be minimal. | ||
| */ | ||
| { computeStyle: { gpuAcceleration: false } }, | ||
|
|
||
| { flip: { padding: 0, flipVariationsByContent: true } }, | ||
| { preventOverflow: { padding: 0 } }, | ||
|
|
||
| offset && { | ||
| offset: { offset: rtl ? applyRtlToOffset(offset, position) : offset }, | ||
| keepTogether: { enabled: false }, | ||
| }, | ||
|
|
||
| /** | ||
| * When the popper box is placed in the context of a scrollable element, we need to set | ||
| * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent' | ||
| * (default is 'viewport') so that the popper box will stick with the targetRef when we | ||
| * scroll targetRef out of the viewport. | ||
| */ | ||
| hasScrollableElement && { | ||
| preventOverflow: { escapeWithReference: true }, | ||
| flip: { boundariesElement: 'scrollParent' }, | ||
| }, | ||
|
|
||
| userModifiers, | ||
|
|
||
| /** | ||
| * unstable_pinned disables the flip modifier by setting flip.enabled to false; this | ||
| * disables automatic repositioning of the popper box; it will always be placed according to | ||
| * the values of `align` and `position` props, regardless of the size of the component, the | ||
| * reference element or the viewport. | ||
| */ | ||
| unstable_pinned && { flip: { enabled: false } }, | ||
| ), | ||
| [hasScrollableElement, position, offset, rtl, unstable_pinned, userModifiers], | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have |
||
| ) | ||
|
|
||
| const scheduleUpdate = React.useCallback(() => { | ||
|
|
@@ -102,48 +165,6 @@ const Popper: React.FunctionComponent<PopperProps> = props => { | |
| return | ||
| } | ||
|
|
||
| const pointerTargetRefElement = pointerTargetRef && pointerTargetRef.current | ||
| const scrollParentElement = getScrollParent(contentRef.current) | ||
| const popperHasScrollableParent = scrollParentElement !== scrollParentElement.ownerDocument.body | ||
|
|
||
| const modifiers: PopperJS.Modifiers = _.merge( | ||
| { preventOverflow: { padding: 0 } }, | ||
| { flip: { padding: 0, flipVariationsByContent: true } }, | ||
| /** | ||
| * This prevents blurrines in chrome, when the coordinates are odd numbers | ||
| * alternative would be to use `fn`, call _PopperJS.default.Defaults.modifiers.computeStyle.fn(data, options) | ||
| * and manipulate the computeed style or ask popper to fix it | ||
| * but since there is presumably only handful of poppers displayed on the page, the performance impact should be minimal | ||
| */ | ||
| { computeStyle: { gpuAcceleration: false } }, | ||
| /** | ||
| * When the popper box is placed in the context of a scrollable element, we need to set | ||
| * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent' (default is 'viewport') | ||
| * so that the popper box will stick with the targetRef when we scroll targetRef out of the viewport. | ||
| */ | ||
| popperHasScrollableParent && { | ||
| preventOverflow: { escapeWithReference: true }, | ||
| flip: { boundariesElement: 'scrollParent' }, | ||
| }, | ||
| /** | ||
| * unstable_pinned disables the flip modifier by setting flip.enabled to false; this disables automatic | ||
| * repositioning of the popper box; it will always be placed according to the values of `align` and | ||
| * `position` props, regardless of the size of the component, the reference element or the viewport. | ||
| */ | ||
| unstable_pinned && { flip: { enabled: false } }, | ||
| computedModifiers, | ||
| userModifiers, | ||
| /** | ||
| * This modifier is necessary in order to render the pointer. | ||
| */ | ||
| { | ||
| arrow: { | ||
| enabled: !!pointerTargetRefElement, | ||
| element: pointerTargetRefElement, | ||
| }, | ||
| }, | ||
| ) | ||
|
|
||
| const handleUpdate = (data: PopperJS.Data) => { | ||
| // PopperJS performs computations that might update the computed placement: auto positioning, flipping the | ||
| // placement in case the popper box should be rendered at the edge of the viewport and does not fit | ||
|
|
@@ -156,21 +177,32 @@ const Popper: React.FunctionComponent<PopperProps> = props => { | |
| const options: PopperJS.PopperOptions = { | ||
| placement: proposedPlacement, | ||
| positionFixed, | ||
| modifiers, | ||
| modifiers: { | ||
| ...computedModifiers, | ||
|
|
||
| /** | ||
| * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be | ||
| * placed under computed modifiers. Deep merge is not required as this modifier has only these properties. | ||
| */ | ||
| arrow: { | ||
| enabled: !!(pointerTargetRef && pointerTargetRef.current), | ||
| element: pointerTargetRef && pointerTargetRef.current, | ||
| }, | ||
| }, | ||
| onCreate: handleUpdate, | ||
| onUpdate: handleUpdate, | ||
| } | ||
|
|
||
| popperRef.current = createPopper(reference, contentRef.current, options) | ||
| }, [ | ||
| // TODO review dependencies for popperHasScrollableParent | ||
| computedModifiers, | ||
| enabled, | ||
| userModifiers, | ||
| computedModifiers, | ||
| pointerTargetRef, | ||
| positionFixed, | ||
| proposedPlacement, | ||
| unstable_pinned, | ||
| targetRef, | ||
| unstable_pinned, | ||
| ]) | ||
|
|
||
| React.useLayoutEffect(() => { | ||
|
|
@@ -182,13 +214,10 @@ const Popper: React.FunctionComponent<PopperProps> = props => { | |
|
|
||
| const child = | ||
| typeof children === 'function' | ||
| ? (children as PopperChildrenFn)({ | ||
| placement: computedPlacement, | ||
| scheduleUpdate, | ||
| }) | ||
| : children | ||
| ? children({ placement: computedPlacement, scheduleUpdate }) | ||
| : (children as React.ReactElement) | ||
|
|
||
| return <Ref innerRef={contentRef}>{React.Children.only(child) as React.ReactElement}</Ref> | ||
| return <Ref innerRef={contentRef}>{React.Children.only(child)}</Ref> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small type improvements there as in real world we allow to pass only |
||
| } | ||
|
|
||
| Popper.defaultProps = { | ||
|
|
||
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,13 @@ | ||
| import * as React from 'react' | ||
|
|
||
| const initialStyles: React.CSSProperties = { | ||
| // Prevents scroll issue, waiting for Popper.js to add this style once initiated. | ||
| // https://github.com/mui-org/material-ui/issues/16740 | ||
| position: 'fixed', | ||
| // Fix Popper.js initial positioning display issue | ||
| // https://github.com/mui-org/material-ui/issues/17774 | ||
| top: 0, | ||
| left: '0px /* @noflip */', | ||
| } | ||
|
|
||
| export default initialStyles |
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.
I don't think that using
RefasuseMemodependency works.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.
As discussed in offline added a comment there.