-
Notifications
You must be signed in to change notification settings - Fork 63
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
LG-4445: add renderMode and top layer #2482
Conversation
|
17d4fbc
to
deebe1c
Compare
Size Change: +1.97 kB (+0.15%) Total Size: 1.36 MB
ℹ️ View Unchanged
|
deebe1c
to
557fb83
Compare
[getTransformStyles(placement, spacing)]: | ||
state === 'exiting' || state === 'entering', | ||
[closedStyles]: state === 'exiting' || state === 'exited', | ||
[openStyles]: state === 'entering' || state === 'entered', | ||
[css` | ||
z-index: ${popoverZIndex}; |
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.
should z-index have a default?
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.
no, this won't get applied when the popoverZIndex
is undefined which is possible in the case when renderMode="top-layer"
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.
@shaneeza What was the initial reasoning for having PopoverContext live in leafygreen-provider
instead of within the popover
package?
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.
fwiw, I did try moving PopoverContext
into the popover package while I was consolidating PortalContext
and PopoverContext
. Since the consolidated PopoverProvider
is included in the global LG provider and the @leafygreen-ui/leafygreen-provider
, we can't move PopoverContext
into popover without introducing a circular dependency
export const DismissMode = { | ||
Auto: 'auto', | ||
Manual: 'manual', | ||
} as const; | ||
export type DismissMode = (typeof DismissMode)[keyof typeof DismissMode]; | ||
|
||
/** Local implementation of web-native `ToggleEvent` until we use typescript v5 */ | ||
export interface ToggleEvent extends Event { | ||
type: 'toggle'; | ||
newState: 'open' | 'closed'; | ||
oldState: 'open' | 'closed'; | ||
} |
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 think these types should all live in the popover package
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 are they duplicated 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.
I have a comment at the top of the file about this. The types can't be shared/imported because of a circular dependency between @leafygreen-ui/leafygreen-provider
and @leafygreen-ui/popover
export type DismissMode = (typeof DismissMode)[keyof typeof DismissMode]; | ||
|
||
/** Local implementation of web-native `ToggleEvent` until we use typescript v5 */ | ||
export interface ToggleEvent extends Event { |
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 this extends Event
, does it? (i.e. it doesn't have e.target
etc. iirc)
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.
This interface inherits properties from its parent, Event.
source: https://developer.mozilla.org/en-US/docs/Web/API/ToggleEvent#instance_properties
took that to mean that it should but can drop if I'm reading that incorrectly
*/ | ||
scrollContainer?: null; | ||
}; | ||
/** @deprecated - use {@link RenderTopLayerProps} */ |
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.
Could potentially add more on why we recommend TopLayerProps
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.
going to think more on how to best surface this context before merging the integration branch
setIsPopoverOpen, | ||
} = usePopoverContext(); | ||
...restProps | ||
} = usePopoverContextProps(rest, popoverContext); |
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.
does this need to be a hook?
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.
felt cleaner to abstract this than have to worry about all the separate variables in the main Popover
component file
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 think perhaps this question is more about whether this has to be a hook vs just being a function? It doesn't appear to use any state or call any hooks itself internally.
@@ -190,16 +231,24 @@ export const Popover = forwardRef<HTMLDivElement, PopoverComponentProps>( | |||
)} |
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.
do we still need this placeholder?
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.
yes we still need this for cases where refEl
is undefined
{/* We need to put `setContentNode` ref on this inner wrapper because | ||
placing the ref on the parent will create an infinite loop in some cases |
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.
do we need to use setContentNode
? Can we use a standard useRef
RefObject?
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.
we explicitly need to use a callback ref. MutableRefObject
caused some positioning issues
<Instance | ||
buttonText={undefined} | ||
className={css` | ||
background-color: ${color.light.background.primary.default}; | ||
`} | ||
dismissMode="manual" |
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 remember what the answer was last time: does this need to be inside the Button?
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.
We don't take a stance on this. It only needs to nested under the reference element if the refEl
prop is left undefined
<Popover | ||
{...rest} | ||
active={active} | ||
renderMode={RenderMode.TopLayer} |
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.
technically we should probably open up the renderMode
as a control in the LiveExample
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.
This in a weird in-between state, so I will leave that off for now until after I've refactored the popover-consuming components. Currently, renderMode="top-layer"
is only respected if usePortal={undefined}
. After the refactor work, usePortal
will no longer be considered and renderMode
can be supported as a control
5fbe049
to
2a4e5eb
Compare
db057de
to
7338ed0
Compare
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'm seeing some behavior that seems strange with Select
in Storybook where the popover is rendering like in the corner of the page. Does this have anything to do with this? https://642700aa3e49e32bdbf0b0fc-qztpposnja.chromatic.com/?path=/story/components-select--live-example
setIsPopoverOpen, | ||
} = usePopoverContext(); | ||
...restProps | ||
} = usePopoverContextProps(rest, popoverContext); |
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 think perhaps this question is more about whether this has to be a hook vs just being a function? It doesn't appear to use any state or call any hooks itself internally.
df9cb86
to
8da3a91
Compare
8da3a91
to
bee293b
Compare
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.
* Fix usePortal={false} transition and className order * Replace usePortal with renderMode and add top layer render mode in Popover * Replace usePortal with renderMode and add top layer render mode in LG Provider * Refactor types in Popover-consuming packages * README * Address feedback
* Fix usePortal={false} transition and className order * Replace usePortal with renderMode and add top layer render mode in Popover * Replace usePortal with renderMode and add top layer render mode in LG Provider * Refactor types in Popover-consuming packages * README * Address feedback
✍️ Proposed changes
renderMode
,dismissMode
, andonToggle
props toPopover
componentusePortal
currently overridesrenderMode
prop but will be dropped in an upcoming PRrenderMode="top-layer"
🎟 Jira ticket: LG-4445
✅ Checklist
For bug fixes, new features & breaking changes
yarn changeset
and documented my changes🧪 How to test changes
Popover
storiesCombobox/LiveExample
DatePicker/LiveExample
GuideCue/LiveExample
NumberInput/LiveExample
SearchInput/LiveExample
Chat/InputBar/WithDropdown