Skip to content

Commit 638731c

Browse files
authored
fix: fix double-click issue on touch devices (#388)
* fix: fix double-click issue on touch devices * fix: disable focus zone on mobile
1 parent adf98ae commit 638731c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

web/src/components/elements/tabs/TabHeader/TabHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ export const TabHeader: React.FC<Props> = ({
5454
}
5555
}, [semanticColors])
5656

57+
const isTouchDevice = navigator.maxTouchPoints > 0
5758
const cmdToolbarStyles: IStackStyles = {
5859
root: {
5960
display: 'flex',
6061
},
6162
}
6263

6364
return (
64-
<FocusZone style={{ flex: 1 }}>
65+
<FocusZone disabled={isTouchDevice} style={{ flex: 1 }}>
6566
<Stack
6667
grow
6768
horizontal

web/src/components/elements/tabs/TabLabel/TabLabel.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface Props {
3636

3737
export const TabLabel: React.FC<Props> = ({ label, active, disabled, onClick, onClose, canClose, icon }) => {
3838
const theme = useTheme()
39+
const isTouchDevice = navigator.maxTouchPoints > 0
3940

4041
const containerStyles: IStackStyles = useMemo(() => {
4142
const { palette, semanticColors } = theme
@@ -84,7 +85,7 @@ export const TabLabel: React.FC<Props> = ({ label, active, disabled, onClick, on
8485
lineHeight: 'auto',
8586
fontSize: FontSizes.smallPlus,
8687
color: 'inherit',
87-
opacity: active ? '1' : '0',
88+
opacity: isTouchDevice || active ? '1' : '0',
8889
':focus': {
8990
opacity: '1',
9091
},
@@ -97,12 +98,12 @@ export const TabLabel: React.FC<Props> = ({ label, active, disabled, onClick, on
9798
color: 'inherit',
9899
},
99100
}
100-
}, [active])
101+
}, [active, isTouchDevice])
101102

102103
const iconStyle = active ? icon?.active : icon?.inactive
103104

104105
// onAuxClick doesn't work in Chrome, so only way to capture it is onMouseUp/Down.
105-
const handleClick: React.MouseEventHandler = (e) => {
106+
const handleClick: React.MouseEventHandler<HTMLElement> = (e) => {
106107
switch (e.button) {
107108
case BUTTON_PRIMARY:
108109
onClick?.()
@@ -113,7 +114,7 @@ export const TabLabel: React.FC<Props> = ({ label, active, disabled, onClick, on
113114
}
114115
}
115116

116-
const handleClose = useCallback(
117+
const handleClose: React.MouseEventHandler<HTMLElement> = useCallback(
117118
(e) => {
118119
e.stopPropagation()
119120
onClose?.()
@@ -156,7 +157,7 @@ export const TabLabel: React.FC<Props> = ({ label, active, disabled, onClick, on
156157
disabled={disabled}
157158
iconProps={{ iconName: 'Cancel' }}
158159
styles={btnStyles}
159-
onClick={handleClose}
160+
onMouseUp={handleClose}
160161
/>
161162
</Stack.Item>
162163
) : null}

0 commit comments

Comments
 (0)