Skip to content
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

Add the portalContainerId in Select Future release #4328

Merged
merged 14 commits into from
Nov 22, 2023

Conversation

mcwinter07
Copy link
Contributor

@mcwinter07 mcwinter07 commented Nov 20, 2023

Why

This is blocking adoption of the Select component in KAIO. Consumers were having issues with the select not having an expose portal prop.

What

  • Introduce the portalContainerId prop in future Select
    • This is then used to pass a new portal element down to the selects Popover primitive
  • adds test cases to ensure portal appends to correct DOM nodes
  • adds a new story to showcase and document how to use

Copy link

changeset-bot bot commented Nov 20, 2023

🦋 Changeset detected

Latest commit: 27d11ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kaizen/components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mcwinter07 mcwinter07 changed the title Expose the Popover components portalContainer prop Expose the Popover components portalContainer in Select Future release Nov 20, 2023
@mcwinter07 mcwinter07 force-pushed the KDS-1969/expose-portal-on-select branch from 9d51653 to 1199280 Compare November 20, 2023 23:22
@mcwinter07 mcwinter07 force-pushed the KDS-1969/expose-portal-on-select branch from fef77c5 to d7d234c Compare November 21, 2023 01:12
@mcwinter07 mcwinter07 marked this pull request as ready for review November 21, 2023 01:14
@mcwinter07 mcwinter07 requested a review from a team as a code owner November 21, 2023 01:14
Copy link
Contributor

github-actions bot commented Nov 21, 2023

✨ Here is your branch preview! ✨

Last updated for commit 27d11ba: Update .changeset/happy-tips-compete.md

@mcwinter07 mcwinter07 changed the title Expose the Popover components portalContainer in Select Future release Add the portalContainerId in Select Future release Nov 21, 2023

<Canvas of={SelectStories.PortalContainer} />

It is important to note that a `relative` position should be applied to container element that contains the portal, ie:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say "not absolute" rather than "is relative", as it will explain it clearer without the need for an example since everything is relative by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the container needs a position: relative for the popover to determine its position document since it uses absolute. Otherwise the static positioning on most elements could risk the Popover spilling out of the confines of it container.

Relative on container:
Screenshot 2023-11-22 at 9 24 59 am

Classless container:
Screenshot 2023-11-22 at 9 24 53 am

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh very curious, but do we want it to cut off..?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't cut it off as a default, but if someone wants to cut it off, I'm sure they can figure it out :) I think we could probably leave the advice off 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove it, but my thinking here is that this is a visual shorthand of how the portal container can effect the popover, instead of it just being on the body.

I'm less beholden to having the advice around relative at the bottom since the example code can be seen in the canvas anyway.


describe("Popover portal", () => {
it("has accessible trigger controls", async () => {
render(<SelectWrapper id="id--select" isOpen />)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to declare the id in these tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And they're outa here ⚾ 🌬️ Nice catch, some left overs of when I had some janky selectors in there

/**
* Creates a portal for the Popover to the matching element id
*/
portalContainerId?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of confining it to an id, we should expose the same api that we've given the Popover, which accepts portalContainer as an element. This way, the consumer can use a ref if they wanted and do not require an id :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my suggestion to simplify the API for the most common use case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in two minds about this, but having just tested variations of consumer code, I suppose this will be easiest for the consumer since they don't need a useEffect. Happy to go this way then :)

@mcwinter07 mcwinter07 merged commit a374c07 into main Nov 22, 2023
15 checks passed
@mcwinter07 mcwinter07 deleted the KDS-1969/expose-portal-on-select branch November 22, 2023 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants