Skip to content

Commit

Permalink
feat: disable pointer navigation on selectable elements (fix #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Jan 24, 2025
1 parent 0209c49 commit 67dc71e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ fixed-positioned element container should not have its own border or padding
styles. If that's the case, you can always add an extra wrapper that just
defines the fixed position without visual styles.

## Text Selection

The lightbox is rendered with the `user-select: none` CSS style. If you'd like
to make some of your custom elements user-selectable, use the `yarll_selectable`
CSS class. This class sets the `user-select: text` style and turns off
click-and-drag slide navigation, likely interfering with text selection UX.

## Hooks (experimental)

The library exports the following experimental hooks that you may find helpful
Expand Down
8 changes: 6 additions & 2 deletions src/components/useSensors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ export default function useSensors() {
if (
// ignore right button clicks (e.g., context menu)
(event.pointerType === "mouse" && event.buttons > 1) ||
// ignore clicks on navigation buttons, toolbar, etc.
// ignore clicks on navigation buttons, toolbar, user-selectable elements, etc.
(event.target instanceof Element &&
(event.target.classList.contains(cssClass("button")) ||
event.target.classList.contains(cssClass("icon")) ||
carouselRef.current?.parentElement?.querySelector(`.${cssClass("toolbar")}`)?.contains(event.target)))
Array.from(
carouselRef.current?.parentElement?.querySelectorAll(
`.${cssClass("toolbar")}, .${cssClass("selectable")}`,
) /* c8 ignore start */ || [] /* c8 ignore stop */,
).find((element) => element.contains(event.target as Element))))
) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ body:has(> .yarll__portal:not(.yarll__no_scroll_lock)) {
height: globalVar(icon_size, $icon-size);
pointer-events: none;
}

&_selectable {
user-select: text;
-webkit-user-select: text;
}
}

0 comments on commit 67dc71e

Please sign in to comment.