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 52
fix(Popup): avoid double rendering #1153
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2412cba
Popup experiment
layershifter 77cdd85
cleanup
layershifter 8e07be7
Merge branch 'master' of https://github.com/stardust-ui/react into ex…
layershifter a6623b3
Merge branches 'exp/poup' and 'master' of https://github.com/stardust…
layershifter b2b451f
more cleanups
layershifter c107b60
rename file
layershifter af8c660
add changelog entries
layershifter a8a459a
add "implements PopperJS.ReferenceObject"
layershifter 6983e0e
Merge branch 'master' of https://github.com/stardust-ui/react into ex…
layershifter e5819d4
replace `triggerDomElement` with `triggerRef.current`
layershifter 7b9c4c5
update typings
layershifter 0bd45df
rewrite to WeakMap
layershifter 34636bf
update comment
layershifter c453539
remove memoization
layershifter c40b705
Merge branches 'exp/poup' and 'master' of https://github.com/stardust…
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
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
39 changes: 39 additions & 0 deletions
39
packages/react/src/components/Popup/createPopperReferenceProxy.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,39 @@ | ||
import { isRefObject, toRefObject } from '@stardust-ui/react-component-ref' | ||
import * as _ from 'lodash' | ||
import * as React from 'react' | ||
import * as PopperJS from 'popper.js' | ||
|
||
class ReferenceProxy implements PopperJS.ReferenceObject { | ||
ref: React.RefObject<HTMLElement> | ||
|
||
constructor(refObject) { | ||
this.ref = refObject | ||
} | ||
|
||
getBoundingClientRect() { | ||
return _.invoke(this.ref.current, 'getBoundingClientRect', {}) | ||
} | ||
|
||
get clientWidth() { | ||
return this.getBoundingClientRect().width | ||
} | ||
|
||
get clientHeight() { | ||
return this.getBoundingClientRect().height | ||
} | ||
} | ||
|
||
/** | ||
* Popper.js does not support ref objects from `createRef()` as referenceElement. If we will pass | ||
* directly `ref`, `ref.current` will be `null` at the render process. | ||
* | ||
* @see https://popper.js.org/popper-documentation.html#referenceObject | ||
* @see https://github.com/FezVrasta/react-popper/blob/v1.3.3/src/Popper.js#L166 | ||
*/ | ||
const createPopperReferenceProxy = (reference: HTMLElement | React.RefObject<HTMLElement>) => { | ||
layershifter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const referenceRef = isRefObject(reference) ? reference : toRefObject(reference) | ||
|
||
return new ReferenceProxy(referenceRef) | ||
} | ||
|
||
export default createPopperReferenceProxy |
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.