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

feat(popover): use floating-ui for autoAlign #14654

Merged

Conversation

tay1orjones
Copy link
Member

@tay1orjones tay1orjones commented Sep 14, 2023

Closes #14493

This PR enhances Popover's experimental autoAlign functionality to automatically position the floating element to be within view, even on scroll.

This uses floating-ui and relies solely on the fixed strategy, using position: fixed on the floating element. In the majority of cases, Popover floating elements will no longer be clipped by parents with overflow: hidden.

This implementation requires two important changes I'd like to highlight:

  1. The caret must be a child of the popover content instead of a sibling, so there is a dom change here.
  2. The .#{$prefix}--popover-container must not have position: relative

Changelog

Changed

  • Add new alignment options to match the floating-ui api with backwards compatibility. These also more properly reflect the "logical property" naming convention of start/end instead of left/right, for instance.
  • Use floating-ui for positioning the caret and floating element, apply styles via CSSOM to comply with CSP.
  • Feed floating-ui the values of popover's custom properties (offset, caret size, etc) when possible.
  • Update Popover styling so no positioning styling is used when autoAlign={true}
  • Update ToggletipButton to use forwardRef
  • Update Slug styling to be compatible with autoAlign

Removed

  • There was an unused ref on Tooltip, I removed it.

Testing / Reviewing

  • View the popover stories, there are a few autoalign experiment stories in there. Ensure it works as intended and there's no regressions.
  • View the Tooltip autoalign story and ensure the autoAlign functionality works with no regressions
  • View the ToggleTip autoalign story and ensure the autoAlign functionality works with no regressions
  • View the slug stories and ensure ensure the autoAlign functionality works with no regressions

@netlify
Copy link

netlify bot commented Sep 14, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 63aa6c1
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/65aea87ae15a560008a2d2e9
😎 Deploy Preview https://deploy-preview-14654--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tay1orjones tay1orjones mentioned this pull request Jan 24, 2024
1 task
Copy link

netlify bot commented Jan 25, 2024

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 13ada6b
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65fb2096b28510000854a425
😎 Deploy Preview https://deploy-preview-14654--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@guidari
Copy link
Contributor

guidari commented Mar 8, 2024

@tay1orjones All good with the changes in the ToggletipButton. There is no a11y errors 🚀

Copy link
Member

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

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

This looks awesome! I noticed a small issue with the Slug storybook alignments using the old values, but I will create a separate issue for that and tackle that with the upcoming Slug changes.

Copy link
Member

@alisonjoseph alisonjoseph left a comment

Choose a reason for hiding this comment

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

🔥🚀 Awesome, LGTM!! (other than a couple merge conflicts)

Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

Looks Awesome @tay1orjones ! 🌟 Just two comments:

Tab tip experimental auto align story
The example of the popover with no caret should be sitting directly underneath the icon box with no space between them.

Example:
Frame 1

Playground story
Align prop: When the caret is set to to true, there is no caret present in the popover for right-top alignment. All other alignments with caret and without caret look great!

@tay1orjones
Copy link
Member Author

@laurenmrice Thank you for catching both of those! They should be fixed now.

@laurenmrice
Copy link
Member

laurenmrice commented Mar 20, 2024

Toggletip Experimental Auto Align story

  • @tay1orjones The only thing I see now is that the label and the info icon is wrapping to two lines no matter how wide your screen size is. I am assuming that is a bug and the label should be on one line? The open toggletip itself looks fine, it is just the label I was wondering about.
Screenshot 2024-03-20 at 12 53 54 PM

@tay1orjones tay1orjones added this pull request to the merge queue Mar 20, 2024
@tay1orjones
Copy link
Member Author

@laurenmrice Thanks! I just pushed up a commit that fixes that issue.

I also removed the autoalign story from VRT for now because

  1. It's experimental
  2. It was larger than percy would snapshot, so it was just an empty snapshot file

I added the popover playground story to vrt instead.

Merged via the queue into carbon-design-system:main with commit afce28d Mar 20, 2024
20 checks passed
@tay1orjones tay1orjones deleted the 14493-floating-ui-poc branch March 20, 2024 18:25
preetibansalui pushed a commit to tay1orjones/carbon that referenced this pull request Apr 24, 2024
)

* WIP: add floating-ui to popover

* WIP: use scss for align positioning, update CSSOM styling, add flip, add autoUpdate, add arrow, add offset

* wip(popover): explore logical properties support, popover offset from logical property

* WIP

* WIP: add fixed strategy, remove default popover styling when autoAlign

* WIP: properly set refs on reference element and floating element

* WIP

* wip(popover): correct caret placement

* wip(popover): update styles to support new alignment names

* feat(popover): cleanup autoalign implementation/styles

* fix(popover): improve autoAlign

* fix(popover): add forwardRef to ToggletipButton

* fix(popover): improve autoAlign compatibility with slug

* fix(popover): position absolute is not necessary on the container

* fix(slug): scope popover selectors for autoalign functionality

* chore: yarn dedupe

* chore(popover): remove console logs

* fix(popover): improve tests, cloneElement logic

* fix(popover): update align props across the entire system

* chore(popover): fix typescript issues

* fix(popover): ensure component api table in docs works

* chore(popover): typescript fixes

* fix(popover): ensure autoAlign properly pads out the slug caret

* fix(popover): typescript error

* fix(popover): remove offset when isTabTip

* fix(popover): correct caret style typo

* docs(popover): clean up stories

* test(popover): update story name

* chore: fix toggletip story width, vrt popover playground

---------

Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Popover to use FloatingUI
6 participants