This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 228
Allow ref objects to be passed #308
Merged
FezVrasta
merged 3 commits into
floating-ui:master
from
maclockard:mac/support-ref-objects
Nov 2, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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,4 @@ | ||
type RefHandler = (?HTMLElement) => void; | ||
type RefObject = { current?: HTMLElement}; | ||
|
||
export type Ref = RefHandler | RefObject; | ||
This file contains 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 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 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 |
---|---|---|
|
@@ -6,36 +6,37 @@ interface ManagerProps { | |
} | ||
export class Manager extends React.Component<ManagerProps, {}> { } | ||
|
||
type RefHandler = (ref: HTMLElement | SVGElement | null) => void; | ||
|
||
interface ReferenceChildrenProps { | ||
ref: RefHandler; | ||
// React refs are supposed to be contravariant (allows a more general type to be passed rather than a more specific one) | ||
// However, Typescript currently can't infer that fact for refs | ||
// See https://github.com/microsoft/TypeScript/issues/30748 for more information | ||
ref: React.Ref<any>; | ||
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. this is very unfortunate, but this issue with contravariance vs covariance with refs is a very long standing issue with TS that doesn't look like it will be resolved soon. |
||
} | ||
|
||
interface ReferenceProps { | ||
children: (props: ReferenceChildrenProps) => React.ReactNode; | ||
innerRef?: RefHandler; | ||
innerRef?: React.Ref<any>; | ||
} | ||
export class Reference extends React.Component<ReferenceProps, {}> { } | ||
|
||
export interface PopperArrowProps { | ||
ref: RefHandler; | ||
ref: React.Ref<any>; | ||
style: React.CSSProperties; | ||
} | ||
|
||
export interface PopperChildrenProps { | ||
arrowProps: PopperArrowProps; | ||
outOfBoundaries: boolean | null; | ||
placement: PopperJS.Placement; | ||
ref: RefHandler; | ||
ref: React.Ref<any>; | ||
scheduleUpdate: () => void; | ||
style: React.CSSProperties; | ||
} | ||
|
||
export interface PopperProps { | ||
children: (props: PopperChildrenProps) => React.ReactNode; | ||
eventsEnabled?: boolean; | ||
innerRef?: RefHandler; | ||
innerRef?: React.Ref<any>; | ||
modifiers?: PopperJS.Modifiers; | ||
placement?: PopperJS.Placement; | ||
positionFixed?: boolean; | ||
|
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.
Why can't we use
React$Ref<HTMLElement>
here?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.
React$Ref<HTMLElement>
includes string refs which are legacy and react-popper does not support.