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: add new preventTextSelectionOverflow prop #1170

Conversation

anatolzak
Copy link
Contributor

closes #1168

Currently, when initiating text selection from within a floating element and dragging the pointer outside, the text outside the floating element gets selected.

This PR introduces a new prop preventTextSelectionOverflow that controls whether text-selection overflow is allowed. By default preventTextSelectionOverflow will be true.

The affected builders are:

  • listbox (combobox, select)
  • menu (context menu, dropdown menu, menubar)
  • popover

Link preview already implemented preventing text-selection overflow, so now the link preview builder gets this behavior from usePopper like the other builders mentioned above.

Tooltip, however, is not added in this PR because the tooltip closes when the pointer leaves the grace zone. The link preview has logic to prevent closing when text selection occurred. In a later PR, I will merge a lot of the behaviors of the tooltip and link preview, at which point tooltip will inherit the prevention of text-selection overflow and not close itself after the pointer leaves after text selection.

Also, the dialog is not added in this PR because the overlay already takes care of not allowing user selection because the overlay spans the entire viewport.

I haven't added tests yet because I am not sure how you would test this behavior without bending backwards

Here are videos showing all the affected builders before and after.

Context menu

context.menu.mov

Dropdown menu

dropdown.menu.mov

Link preview - same behavior as before

link.preview.mov

Combobox

combobox.mov

Select

select.mov

Menubar

menubar.mov

Popover

popover.mov

Copy link

changeset-bot bot commented Apr 8, 2024

🦋 Changeset detected

Latest commit: 388886b

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

This PR includes changesets to release 1 package
Name Type
@melt-ui/svelte 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

@anatolzak anatolzak changed the title add new preventTextSelectionOverflow prop Feat: add new preventTextSelectionOverflow prop Apr 8, 2024
Copy link
Contributor

github-actions bot commented Apr 9, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
melt-ui ✅ Ready (View Log) Visit Preview 388886b

@huntabyte
Copy link
Member

Part of me wonders when this would be desired if you're using the floating element in a "modal" fashion (close on outside click, etc.). I suppose since we don't have a source of truth of whether the box is acting as a modal or not having another prop makes sense.

I do feel like the default for this should align with the default of the other "close on escape" / "close on outside click" where if we default the builder to act as a modal, this should default to true

@anatolzak
Copy link
Contributor Author

Part of me wonders when this would be desired if you're using the floating element in a "modal" fashion (close on outside click, etc.). I suppose since we don't have a source of truth of whether the box is acting as a modal or not having another prop makes sense.

I do feel like the default for this should align with the default of the other "close on escape" / "close on outside click" where if we default the builder to act as a modal, this should default to true

For anyone reading, Hunter thought that I was proposing setting preventTextSelectionOverflow as false by default, which is not the case. So disregard his comment :)

@TGlide TGlide merged commit 3c5277a into melt-ui:develop Apr 15, 2024
6 checks passed
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
@anatolzak anatolzak deleted the fix/prevent-text-selection-outside-floating-element branch April 15, 2024 11:47
lolcabanon pushed a commit to lolcabanon/melt-ui that referenced this pull request Apr 20, 2024
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.

Text selection overflows floating element
3 participants