Skip to content

Commit 39deba5

Browse files
committed
feat(tooltip): suppress touch callout and text selection on longpress invoker for webkit
1 parent b8c9712 commit 39deba5

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/ui/components/overlays/src/configurations/visibility-trigger-partials/withHoverInteraction.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export function withHoverInteraction({
112112
controller.invokerNode?.addEventListener('mouseenter', handleHoverAndFocus);
113113
controller.invokerNode?.addEventListener('mouseleave', handleHoverAndFocus);
114114
} else {
115+
controller.invokerNode?.style.setProperty('-webkit-touch-callout', 'none');
116+
controller.invokerNode?.style.setProperty('user-select', 'none');
117+
controller.invokerNode?.style.setProperty('-webkit-user-select', 'none');
115118
controller.invokerNode?.addEventListener('contextmenu', preventContextMenu);
116119
controller.invokerNode?.addEventListener('pointerdown', handleLongpress);
117120
controller.invokerNode?.addEventListener('pointerup', handleLongpress);
@@ -130,6 +133,9 @@ export function withHoverInteraction({
130133
controller.invokerNode?.removeEventListener('mouseenter', handleHoverAndFocus);
131134
controller.invokerNode?.removeEventListener('mouseleave', handleHoverAndFocus);
132135
} else {
136+
controller.invokerNode?.style.removeProperty('-webkit-touch-callout');
137+
controller.invokerNode?.style.removeProperty('user-select');
138+
controller.invokerNode?.style.removeProperty('-webkit-user-select');
133139
controller.invokerNode?.removeEventListener('contextmenu', preventContextMenu);
134140
controller.invokerNode?.removeEventListener('pointerdown', handleLongpress);
135141
controller.invokerNode?.removeEventListener('pointerup', handleLongpress);

packages/ui/components/overlays/test/withHoverInteraction.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ describe('withHoverInteraction (isHoverSupported: false)', () => {
7171
expect(ctrl.isShown).to.equal(false);
7272
});
7373

74+
it('disables text selection on the invoker on init and restores it on teardown', () => {
75+
const { invokerNode } = ctrl;
76+
const getUserSelect = () =>
77+
invokerNode?.style.getPropertyValue('user-select') ||
78+
invokerNode?.style.getPropertyValue('-webkit-user-select');
79+
expect(getUserSelect()).to.equal('none');
80+
81+
ctrl.teardown();
82+
expect(getUserSelect()).to.equal('');
83+
});
84+
7485
it('does not open on tap-triggered focusin', () => {
7586
ctrl.invokerNode?.dispatchEvent(new Event('focusin', { bubbles: true }));
7687
clock.tick(300);

0 commit comments

Comments
 (0)