Fix selection of text when 3D touching a token on iOS

This commit is contained in:
Mitchell McCaffrey 2021-06-17 11:30:06 +10:00
parent 4e2d14e7ac
commit 78dac55d7a
2 changed files with 17 additions and 1 deletions

View File

@ -165,7 +165,14 @@ function TokenBar({ onMapTokensStateCreate }) {
padding: "0 16px",
}}
>
<Grid columns="1fr" gap={2} py={2}>
<Grid
columns="1fr"
gap={2}
py={2}
// Prevent selection on 3D touch for iOS
onTouchStart={preventSelect}
onTouchEnd={resumeSelect}
>
{tokenGroups.map((group) => renderToken(group))}
</Grid>
</SimpleBar>

View File

@ -1,5 +1,14 @@
function usePreventSelect() {
function clearSelection() {
if (window.getSelection) {
window.getSelection().removeAllRanges();
}
if (document.selection) {
document.selection.empty();
}
}
function preventSelect() {
clearSelection();
document.body.classList.add("no-select");
}