Skip to content

Commit 988096c

Browse files
authored
fix: Canceling text selection in Safari broken after usePress refactor (#7774)
1 parent 3fee0f4 commit 988096c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/@react-aria/interactions/src/textSelection.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export function disableTextSelection(target?: Element) {
4646
} else if (target instanceof HTMLElement || target instanceof SVGElement) {
4747
// If not iOS, store the target's original user-select and change to user-select: none
4848
// Ignore state since it doesn't apply for non iOS
49-
modifiedElementMap.set(target, target.style.userSelect);
50-
target.style.userSelect = 'none';
49+
let property = 'userSelect' in target.style ? 'userSelect' : 'webkitUserSelect';
50+
modifiedElementMap.set(target, target.style[property]);
51+
target.style[property] = 'none';
5152
}
5253
}
5354

@@ -85,9 +86,10 @@ export function restoreTextSelection(target?: Element) {
8586
// Ignore state since it doesn't apply for non iOS
8687
if (target && modifiedElementMap.has(target)) {
8788
let targetOldUserSelect = modifiedElementMap.get(target) as string;
89+
let property = 'userSelect' in target.style ? 'userSelect' : 'webkitUserSelect';
8890

89-
if (target.style.userSelect === 'none') {
90-
target.style.userSelect = targetOldUserSelect;
91+
if (target.style[property] === 'none') {
92+
target.style[property] = targetOldUserSelect;
9193
}
9294

9395
if (target.getAttribute('style') === '') {

0 commit comments

Comments
 (0)