@mui/material 9.0.0-beta.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Accordion/Accordion.d.mts +3 -3
- package/Accordion/Accordion.d.ts +3 -3
- package/AccordionActions/AccordionActions.d.mts +2 -2
- package/AccordionActions/AccordionActions.d.ts +2 -2
- package/AccordionDetails/AccordionDetails.d.mts +2 -2
- package/AccordionDetails/AccordionDetails.d.ts +2 -2
- package/AccordionSummary/AccordionSummary.d.mts +3 -3
- package/AccordionSummary/AccordionSummary.d.ts +3 -3
- package/Alert/Alert.d.mts +3 -3
- package/Alert/Alert.d.ts +3 -3
- package/AlertTitle/AlertTitle.d.mts +3 -3
- package/AlertTitle/AlertTitle.d.ts +3 -3
- package/AppBar/AppBar.d.mts +3 -3
- package/AppBar/AppBar.d.ts +3 -3
- package/Autocomplete/Autocomplete.d.mts +2 -2
- package/Autocomplete/Autocomplete.d.ts +2 -2
- package/Avatar/Avatar.d.mts +2 -2
- package/Avatar/Avatar.d.ts +2 -2
- package/AvatarGroup/AvatarGroup.d.mts +2 -2
- package/AvatarGroup/AvatarGroup.d.ts +2 -2
- package/Backdrop/Backdrop.d.mts +3 -3
- package/Backdrop/Backdrop.d.ts +3 -3
- package/Badge/Badge.d.mts +3 -3
- package/Badge/Badge.d.ts +3 -3
- package/BottomNavigation/BottomNavigation.d.mts +2 -2
- package/BottomNavigation/BottomNavigation.d.ts +2 -2
- package/BottomNavigationAction/BottomNavigationAction.d.mts +3 -3
- package/BottomNavigationAction/BottomNavigationAction.d.ts +3 -3
- package/Box/Box.d.mts +3 -3
- package/Box/Box.d.ts +3 -3
- package/Breadcrumbs/Breadcrumbs.d.mts +3 -3
- package/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/Button/Button.d.mts +6 -6
- package/Button/Button.d.ts +6 -6
- package/ButtonBase/ButtonBase.d.mts +2 -2
- package/ButtonBase/ButtonBase.d.ts +2 -2
- package/ButtonGroup/ButtonGroup.d.mts +2 -2
- package/ButtonGroup/ButtonGroup.d.ts +2 -2
- package/CHANGELOG.md +28 -0
- package/Card/Card.d.mts +3 -3
- package/Card/Card.d.ts +3 -3
- package/CardActionArea/CardActionArea.d.mts +3 -3
- package/CardActionArea/CardActionArea.d.ts +3 -3
- package/CardActions/CardActions.d.mts +2 -2
- package/CardActions/CardActions.d.ts +2 -2
- package/CardContent/CardContent.d.mts +2 -2
- package/CardContent/CardContent.d.ts +2 -2
- package/CardHeader/CardHeader.d.mts +2 -2
- package/CardHeader/CardHeader.d.ts +2 -2
- package/CardMedia/CardMedia.d.mts +2 -2
- package/CardMedia/CardMedia.d.ts +2 -2
- package/Checkbox/Checkbox.d.mts +4 -4
- package/Checkbox/Checkbox.d.ts +4 -4
- package/Chip/Chip.d.mts +2 -2
- package/Chip/Chip.d.ts +2 -2
- package/CircularProgress/CircularProgress.d.mts +2 -2
- package/CircularProgress/CircularProgress.d.ts +2 -2
- package/ClickAwayListener/ClickAwayListener.d.mts +3 -3
- package/ClickAwayListener/ClickAwayListener.d.ts +3 -3
- package/ClickAwayListener/ClickAwayListener.js +3 -3
- package/ClickAwayListener/ClickAwayListener.mjs +3 -3
- package/Collapse/Collapse.d.mts +5 -5
- package/Collapse/Collapse.d.ts +5 -5
- package/Collapse/Collapse.js +6 -18
- package/Collapse/Collapse.mjs +7 -19
- package/Container/Container.d.mts +2 -2
- package/Container/Container.d.ts +2 -2
- package/CssBaseline/CssBaseline.d.mts +2 -2
- package/CssBaseline/CssBaseline.d.ts +2 -2
- package/Dialog/Dialog.d.mts +3 -3
- package/Dialog/Dialog.d.ts +3 -3
- package/DialogActions/DialogActions.d.mts +2 -2
- package/DialogActions/DialogActions.d.ts +2 -2
- package/DialogContent/DialogContent.d.mts +2 -2
- package/DialogContent/DialogContent.d.ts +2 -2
- package/DialogContentText/DialogContentText.d.mts +3 -3
- package/DialogContentText/DialogContentText.d.ts +3 -3
- package/DialogTitle/DialogTitle.d.mts +3 -3
- package/DialogTitle/DialogTitle.d.ts +3 -3
- package/Divider/Divider.d.mts +4 -4
- package/Divider/Divider.d.ts +4 -4
- package/Drawer/Drawer.d.mts +3 -3
- package/Drawer/Drawer.d.ts +3 -3
- package/Drawer/Drawer.js +1 -4
- package/Drawer/Drawer.mjs +1 -4
- package/Fab/Fab.d.mts +3 -3
- package/Fab/Fab.d.ts +3 -3
- package/Fade/Fade.d.mts +3 -3
- package/Fade/Fade.d.ts +3 -3
- package/Fade/Fade.js +28 -32
- package/Fade/Fade.mjs +29 -33
- package/FilledInput/FilledInput.d.mts +3 -3
- package/FilledInput/FilledInput.d.ts +3 -3
- package/FormControl/FormControl.d.mts +7 -7
- package/FormControl/FormControl.d.ts +7 -7
- package/FormControlLabel/FormControlLabel.d.mts +4 -4
- package/FormControlLabel/FormControlLabel.d.ts +4 -4
- package/FormGroup/FormGroup.d.mts +3 -3
- package/FormGroup/FormGroup.d.ts +3 -3
- package/FormHelperText/FormHelperText.d.mts +3 -3
- package/FormHelperText/FormHelperText.d.ts +3 -3
- package/FormLabel/FormLabel.d.mts +5 -5
- package/FormLabel/FormLabel.d.ts +5 -5
- package/GlobalStyles/GlobalStyles.d.mts +2 -2
- package/GlobalStyles/GlobalStyles.d.ts +2 -2
- package/Grid/Grid.d.mts +2 -2
- package/Grid/Grid.d.ts +2 -2
- package/Grid/Grid.js +2 -2
- package/Grid/Grid.mjs +2 -2
- package/Grow/Grow.d.mts +5 -5
- package/Grow/Grow.d.ts +5 -5
- package/Grow/Grow.js +30 -38
- package/Grow/Grow.mjs +31 -39
- package/Icon/Icon.d.mts +3 -3
- package/Icon/Icon.d.ts +3 -3
- package/IconButton/IconButton.d.mts +5 -5
- package/IconButton/IconButton.d.ts +5 -5
- package/ImageList/ImageList.d.mts +2 -2
- package/ImageList/ImageList.d.ts +2 -2
- package/ImageListItem/ImageListItem.d.mts +2 -2
- package/ImageListItem/ImageListItem.d.ts +2 -2
- package/ImageListItemBar/ImageListItemBar.d.mts +2 -2
- package/ImageListItemBar/ImageListItemBar.d.ts +2 -2
- package/InitColorSchemeScript/InitColorSchemeScript.d.mts +2 -2
- package/InitColorSchemeScript/InitColorSchemeScript.d.ts +2 -2
- package/InitColorSchemeScript/InitColorSchemeScript.js +2 -2
- package/InitColorSchemeScript/InitColorSchemeScript.mjs +2 -2
- package/Input/Input.d.mts +3 -3
- package/Input/Input.d.ts +3 -3
- package/InputAdornment/InputAdornment.d.mts +2 -2
- package/InputAdornment/InputAdornment.d.ts +2 -2
- package/InputBase/InputBase.d.mts +2 -2
- package/InputBase/InputBase.d.ts +2 -2
- package/InputLabel/InputLabel.d.mts +4 -4
- package/InputLabel/InputLabel.d.ts +4 -4
- package/LinearProgress/LinearProgress.d.mts +2 -2
- package/LinearProgress/LinearProgress.d.ts +2 -2
- package/Link/Link.d.mts +4 -4
- package/Link/Link.d.ts +4 -4
- package/List/List.d.mts +4 -4
- package/List/List.d.ts +4 -4
- package/ListItem/ListItem.d.mts +3 -3
- package/ListItem/ListItem.d.ts +3 -3
- package/ListItem/ListItem.js +1 -2
- package/ListItem/ListItem.mjs +1 -2
- package/ListItemAvatar/ListItemAvatar.d.mts +2 -2
- package/ListItemAvatar/ListItemAvatar.d.ts +2 -2
- package/ListItemButton/ListItemButton.d.mts +4 -4
- package/ListItemButton/ListItemButton.d.ts +4 -4
- package/ListItemIcon/ListItemIcon.d.mts +3 -3
- package/ListItemIcon/ListItemIcon.d.ts +3 -3
- package/ListItemSecondaryAction/ListItemSecondaryAction.d.mts +2 -2
- package/ListItemSecondaryAction/ListItemSecondaryAction.d.ts +2 -2
- package/ListItemText/ListItemText.d.mts +3 -3
- package/ListItemText/ListItemText.d.ts +3 -3
- package/ListSubheader/ListSubheader.d.mts +3 -3
- package/ListSubheader/ListSubheader.d.ts +3 -3
- package/Menu/Menu.d.mts +4 -4
- package/Menu/Menu.d.ts +4 -4
- package/MenuItem/MenuItem.d.mts +3 -3
- package/MenuItem/MenuItem.d.ts +3 -3
- package/MenuList/MenuList.d.mts +4 -4
- package/MenuList/MenuList.d.ts +4 -4
- package/MobileStepper/MobileStepper.d.mts +3 -3
- package/MobileStepper/MobileStepper.d.ts +3 -3
- package/Modal/Modal.d.mts +7 -7
- package/Modal/Modal.d.ts +7 -7
- package/NativeSelect/NativeSelect.d.mts +3 -3
- package/NativeSelect/NativeSelect.d.ts +3 -3
- package/NoSsr/NoSsr.d.mts +2 -2
- package/NoSsr/NoSsr.d.ts +2 -2
- package/NoSsr/NoSsr.js +2 -2
- package/NoSsr/NoSsr.mjs +2 -2
- package/OutlinedInput/OutlinedInput.d.mts +4 -4
- package/OutlinedInput/OutlinedInput.d.ts +4 -4
- package/Pagination/Pagination.d.mts +2 -2
- package/Pagination/Pagination.d.ts +2 -2
- package/PaginationItem/PaginationItem.d.mts +3 -3
- package/PaginationItem/PaginationItem.d.ts +3 -3
- package/Paper/Paper.d.mts +4 -4
- package/Paper/Paper.d.ts +4 -4
- package/PigmentContainer/PigmentContainer.d.mts +2 -2
- package/PigmentContainer/PigmentContainer.d.ts +2 -2
- package/PigmentContainer/PigmentContainer.js +2 -2
- package/PigmentContainer/PigmentContainer.mjs +2 -2
- package/PigmentGrid/PigmentGrid.d.mts +2 -2
- package/PigmentGrid/PigmentGrid.d.ts +2 -2
- package/PigmentGrid/PigmentGrid.js +2 -2
- package/PigmentGrid/PigmentGrid.mjs +2 -2
- package/PigmentStack/PigmentStack.d.mts +2 -2
- package/PigmentStack/PigmentStack.d.ts +2 -2
- package/PigmentStack/PigmentStack.js +2 -2
- package/PigmentStack/PigmentStack.mjs +2 -2
- package/Popover/Popover.d.mts +4 -4
- package/Popover/Popover.d.ts +4 -4
- package/Popper/Popper.d.mts +4 -4
- package/Popper/Popper.d.ts +4 -4
- package/Popper/Popper.js +4 -4
- package/Popper/Popper.mjs +4 -4
- package/Portal/Portal.d.mts +2 -2
- package/Portal/Portal.d.ts +2 -2
- package/Portal/Portal.js +2 -2
- package/Portal/Portal.mjs +2 -2
- package/README.md +3 -3
- package/Radio/Radio.d.mts +3 -3
- package/Radio/Radio.d.ts +3 -3
- package/RadioGroup/RadioGroup.d.mts +3 -3
- package/RadioGroup/RadioGroup.d.ts +3 -3
- package/Rating/Rating.d.mts +2 -2
- package/Rating/Rating.d.ts +2 -2
- package/ScopedCssBaseline/ScopedCssBaseline.d.mts +2 -2
- package/ScopedCssBaseline/ScopedCssBaseline.d.ts +2 -2
- package/Select/Select.d.mts +3 -3
- package/Select/Select.d.ts +3 -3
- package/Skeleton/Skeleton.d.mts +2 -2
- package/Skeleton/Skeleton.d.ts +2 -2
- package/Slide/Slide.d.mts +4 -4
- package/Slide/Slide.d.ts +4 -4
- package/Slide/Slide.js +43 -42
- package/Slide/Slide.mjs +44 -44
- package/Slider/Slider.d.mts +4 -4
- package/Slider/Slider.d.ts +4 -4
- package/Slider/Slider.js +1 -1
- package/Slider/Slider.mjs +1 -1
- package/Slider/useSlider.d.mts +1 -1
- package/Slider/useSlider.d.ts +1 -1
- package/Slider/useSlider.js +235 -209
- package/Slider/useSlider.mjs +235 -209
- package/Slider/useSlider.types.d.mts +2 -2
- package/Slider/useSlider.types.d.ts +2 -2
- package/Snackbar/Snackbar.d.mts +2 -2
- package/Snackbar/Snackbar.d.ts +2 -2
- package/SnackbarContent/SnackbarContent.d.mts +3 -3
- package/SnackbarContent/SnackbarContent.d.ts +3 -3
- package/SpeedDial/SpeedDial.d.mts +2 -2
- package/SpeedDial/SpeedDial.d.ts +2 -2
- package/SpeedDialAction/SpeedDialAction.d.mts +3 -3
- package/SpeedDialAction/SpeedDialAction.d.ts +3 -3
- package/SpeedDialIcon/SpeedDialIcon.d.mts +2 -2
- package/SpeedDialIcon/SpeedDialIcon.d.ts +2 -2
- package/Stack/Stack.d.mts +2 -2
- package/Stack/Stack.d.ts +2 -2
- package/Step/Step.d.mts +2 -2
- package/Step/Step.d.ts +2 -2
- package/StepButton/StepButton.d.mts +3 -3
- package/StepButton/StepButton.d.ts +3 -3
- package/StepConnector/StepConnector.d.mts +2 -2
- package/StepConnector/StepConnector.d.ts +2 -2
- package/StepConnector/StepConnector.js +1 -2
- package/StepConnector/StepConnector.mjs +1 -2
- package/StepContent/StepContent.d.mts +2 -2
- package/StepContent/StepContent.d.ts +2 -2
- package/StepIcon/StepIcon.d.mts +3 -3
- package/StepIcon/StepIcon.d.ts +3 -3
- package/StepLabel/StepLabel.d.mts +2 -2
- package/StepLabel/StepLabel.d.ts +2 -2
- package/Stepper/Stepper.d.mts +2 -2
- package/Stepper/Stepper.d.ts +2 -2
- package/SvgIcon/SvgIcon.d.mts +3 -3
- package/SvgIcon/SvgIcon.d.ts +3 -3
- package/SwipeableDrawer/SwipeableDrawer.d.mts +3 -3
- package/SwipeableDrawer/SwipeableDrawer.d.ts +3 -3
- package/SwipeableDrawer/SwipeableDrawer.js +0 -3
- package/SwipeableDrawer/SwipeableDrawer.mjs +0 -3
- package/Switch/Switch.d.mts +4 -4
- package/Switch/Switch.d.ts +4 -4
- package/Switch/Switch.js +4 -0
- package/Switch/Switch.mjs +4 -0
- package/Tab/Tab.d.mts +3 -3
- package/Tab/Tab.d.ts +3 -3
- package/TabScrollButton/TabScrollButton.d.mts +2 -2
- package/TabScrollButton/TabScrollButton.d.ts +2 -2
- package/Table/Table.d.mts +2 -2
- package/Table/Table.d.ts +2 -2
- package/TableBody/TableBody.d.mts +2 -2
- package/TableBody/TableBody.d.ts +2 -2
- package/TableCell/TableCell.d.mts +2 -2
- package/TableCell/TableCell.d.ts +2 -2
- package/TableContainer/TableContainer.d.mts +2 -2
- package/TableContainer/TableContainer.d.ts +2 -2
- package/TableFooter/TableFooter.d.mts +2 -2
- package/TableFooter/TableFooter.d.ts +2 -2
- package/TableHead/TableHead.d.mts +2 -2
- package/TableHead/TableHead.d.ts +2 -2
- package/TablePagination/TablePagination.d.mts +4 -4
- package/TablePagination/TablePagination.d.ts +4 -4
- package/TablePaginationActions/TablePaginationActions.d.mts +2 -2
- package/TablePaginationActions/TablePaginationActions.d.ts +2 -2
- package/TableRow/TableRow.d.mts +2 -2
- package/TableRow/TableRow.d.ts +2 -2
- package/TableSortLabel/TableSortLabel.d.mts +3 -3
- package/TableSortLabel/TableSortLabel.d.ts +3 -3
- package/TableSortLabel/TableSortLabel.js +1 -2
- package/TableSortLabel/TableSortLabel.mjs +1 -2
- package/Tabs/Tabs.d.mts +2 -2
- package/Tabs/Tabs.d.ts +2 -2
- package/TextField/TextField.d.mts +10 -10
- package/TextField/TextField.d.ts +10 -10
- package/TextareaAutosize/TextareaAutosize.d.mts +2 -2
- package/TextareaAutosize/TextareaAutosize.d.ts +2 -2
- package/TextareaAutosize/TextareaAutosize.js +2 -2
- package/TextareaAutosize/TextareaAutosize.mjs +2 -2
- package/ToggleButton/ToggleButton.d.mts +3 -3
- package/ToggleButton/ToggleButton.d.ts +3 -3
- package/ToggleButtonGroup/ToggleButtonGroup.d.mts +2 -2
- package/ToggleButtonGroup/ToggleButtonGroup.d.ts +2 -2
- package/Toolbar/Toolbar.d.mts +2 -2
- package/Toolbar/Toolbar.d.ts +2 -2
- package/Tooltip/Tooltip.d.mts +2 -2
- package/Tooltip/Tooltip.d.ts +2 -2
- package/Typography/Typography.d.mts +4 -4
- package/Typography/Typography.d.ts +4 -4
- package/Zoom/Zoom.d.mts +3 -3
- package/Zoom/Zoom.d.ts +3 -3
- package/Zoom/Zoom.js +24 -30
- package/Zoom/Zoom.mjs +25 -31
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +51 -51
- package/styles/createThemeNoVars.js +1 -1
- package/styles/createThemeNoVars.mjs +1 -1
- package/transitions/utils.d.mts +7 -0
- package/transitions/utils.d.ts +7 -0
- package/transitions/utils.js +27 -0
- package/transitions/utils.mjs +25 -0
- package/version/index.js +2 -2
- package/version/index.mjs +2 -2
package/Slider/useSlider.mjs
CHANGED
|
@@ -11,35 +11,45 @@ import visuallyHidden from '@mui/utils/visuallyHidden';
|
|
|
11
11
|
import clamp from '@mui/utils/clamp';
|
|
12
12
|
import extractEventHandlers from '@mui/utils/extractEventHandlers';
|
|
13
13
|
import areArraysEqual from "../utils/areArraysEqual.mjs";
|
|
14
|
+
import getActiveElement from "../utils/getActiveElement.mjs";
|
|
14
15
|
const INTENTIONAL_DRAG_COUNT_THRESHOLD = 2;
|
|
16
|
+
const EMPTY_MARKS = [];
|
|
17
|
+
const EMPTY_OBJ = {};
|
|
15
18
|
function getNewValue(currentValue, step, direction, min, max) {
|
|
16
19
|
return direction === 1 ? Math.min(currentValue + step, max) : Math.max(currentValue - step, min);
|
|
17
20
|
}
|
|
18
21
|
function asc(a, b) {
|
|
19
22
|
return a - b;
|
|
20
23
|
}
|
|
21
|
-
function findClosest(values, currentValue) {
|
|
22
|
-
const {
|
|
23
|
-
index: closestIndex
|
|
24
|
-
} = values.reduce((acc, value, index) => {
|
|
24
|
+
function findClosest(values, currentValue, preferredIndex = -1) {
|
|
25
|
+
const closestValue = values.reduce((acc, value, index) => {
|
|
25
26
|
const distance = Math.abs(currentValue - value);
|
|
26
|
-
if (acc
|
|
27
|
+
if (acc == null || distance <= acc.distance) {
|
|
27
28
|
return {
|
|
28
29
|
distance,
|
|
29
30
|
index
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
return acc;
|
|
33
|
-
}, null) ??
|
|
34
|
+
}, null) ?? EMPTY_OBJ;
|
|
35
|
+
const {
|
|
36
|
+
index: closestIndex
|
|
37
|
+
} = closestValue;
|
|
38
|
+
if (closestIndex == null) {
|
|
39
|
+
return closestIndex;
|
|
40
|
+
}
|
|
41
|
+
if (preferredIndex >= 0 && values[preferredIndex] === values[closestIndex]) {
|
|
42
|
+
return preferredIndex;
|
|
43
|
+
}
|
|
34
44
|
return closestIndex;
|
|
35
45
|
}
|
|
36
|
-
function trackFinger(event,
|
|
46
|
+
function trackFinger(event, touchIdRef) {
|
|
37
47
|
// The event is TouchEvent
|
|
38
|
-
if (
|
|
48
|
+
if (touchIdRef.current != null && event.changedTouches) {
|
|
39
49
|
const touchEvent = event;
|
|
40
50
|
for (let i = 0; i < touchEvent.changedTouches.length; i += 1) {
|
|
41
51
|
const touch = touchEvent.changedTouches[i];
|
|
42
|
-
if (touch.identifier ===
|
|
52
|
+
if (touch.identifier === touchIdRef.current) {
|
|
43
53
|
return {
|
|
44
54
|
x: touch.clientX,
|
|
45
55
|
y: touch.clientY
|
|
@@ -49,7 +59,7 @@ function trackFinger(event, touchId) {
|
|
|
49
59
|
return false;
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
// The event is MouseEvent
|
|
62
|
+
// The event is PointerEvent or MouseEvent
|
|
53
63
|
return {
|
|
54
64
|
x: event.clientX,
|
|
55
65
|
y: event.clientY
|
|
@@ -76,26 +86,18 @@ function roundValueToStep(value, step, min) {
|
|
|
76
86
|
const nearest = Math.round((value - min) / step) * step + min;
|
|
77
87
|
return Number(nearest.toFixed(getDecimalPrecision(step)));
|
|
78
88
|
}
|
|
79
|
-
function setValueIndex({
|
|
80
|
-
values,
|
|
81
|
-
newValue,
|
|
82
|
-
index
|
|
83
|
-
}) {
|
|
89
|
+
function setValueIndex(values, newValue, index) {
|
|
84
90
|
const output = values.slice();
|
|
85
91
|
output[index] = newValue;
|
|
86
92
|
return output.sort(asc);
|
|
87
93
|
}
|
|
88
|
-
function focusThumb({
|
|
89
|
-
sliderRef,
|
|
90
|
-
activeIndex,
|
|
91
|
-
setActive,
|
|
92
|
-
focusVisible
|
|
93
|
-
}) {
|
|
94
|
+
function focusThumb(sliderRef, activeIndex, setActive, focusVisible) {
|
|
94
95
|
const doc = ownerDocument(sliderRef.current);
|
|
95
|
-
|
|
96
|
+
const activeElement = getActiveElement(doc);
|
|
97
|
+
if (!sliderRef.current?.contains(activeElement) || Number(activeElement?.getAttribute('data-index')) !== activeIndex) {
|
|
96
98
|
const input = sliderRef.current?.querySelector(`[type="range"][data-index="${activeIndex}"]`);
|
|
97
99
|
if (input != null) {
|
|
98
|
-
if (focusVisible
|
|
100
|
+
if (focusVisible == null) {
|
|
99
101
|
input.focus({
|
|
100
102
|
preventScroll: true
|
|
101
103
|
});
|
|
@@ -104,7 +106,7 @@ function focusThumb({
|
|
|
104
106
|
preventScroll: true,
|
|
105
107
|
// Prevent pointer-driven focus rings in browsers that support this option.
|
|
106
108
|
// Chrome 144+ supports `focusVisible` in `HTMLElement.focus()` options.
|
|
107
|
-
// @ts-
|
|
109
|
+
// @ts-expect-error `focusVisible` is not yet in TypeScript's lib.dom FocusOptions.
|
|
108
110
|
focusVisible
|
|
109
111
|
});
|
|
110
112
|
}
|
|
@@ -150,28 +152,6 @@ const axisProps = {
|
|
|
150
152
|
}
|
|
151
153
|
};
|
|
152
154
|
export const Identity = x => x;
|
|
153
|
-
|
|
154
|
-
// TODO: remove support for Safari < 13.
|
|
155
|
-
// https://caniuse.com/#search=touch-action
|
|
156
|
-
//
|
|
157
|
-
// Safari, on iOS, supports touch action since v13.
|
|
158
|
-
// Over 80% of the iOS phones are compatible
|
|
159
|
-
// in August 2020.
|
|
160
|
-
// Utilizing the CSS.supports method to check if touch-action is supported.
|
|
161
|
-
// Since CSS.supports is supported on all but Edge@12 and IE and touch-action
|
|
162
|
-
// is supported on both Edge@12 and IE if CSS.supports is not available that means that
|
|
163
|
-
// touch-action will be supported
|
|
164
|
-
let cachedSupportsTouchActionNone;
|
|
165
|
-
function doesSupportTouchActionNone() {
|
|
166
|
-
if (cachedSupportsTouchActionNone === undefined) {
|
|
167
|
-
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
|
|
168
|
-
cachedSupportsTouchActionNone = CSS.supports('touch-action', 'none');
|
|
169
|
-
} else {
|
|
170
|
-
cachedSupportsTouchActionNone = true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return cachedSupportsTouchActionNone;
|
|
174
|
-
}
|
|
175
155
|
export function useSlider(parameters) {
|
|
176
156
|
const {
|
|
177
157
|
'aria-labelledby': ariaLabelledby,
|
|
@@ -193,35 +173,42 @@ export function useSlider(parameters) {
|
|
|
193
173
|
tabIndex,
|
|
194
174
|
value: valueProp
|
|
195
175
|
} = parameters;
|
|
196
|
-
const
|
|
197
|
-
const
|
|
176
|
+
const touchIdRef = React.useRef(undefined);
|
|
177
|
+
const focusFrameRef = React.useRef(null);
|
|
198
178
|
// We can't use the :active browser pseudo-classes.
|
|
199
179
|
// - The active state isn't triggered when clicking on the rail.
|
|
200
180
|
// - The active state isn't transferred when inversing a range slider.
|
|
201
181
|
const [active, setActive] = React.useState(-1);
|
|
202
182
|
const [open, setOpen] = React.useState(-1);
|
|
203
183
|
const [dragging, setDragging] = React.useState(false);
|
|
204
|
-
const
|
|
184
|
+
const moveCountRef = React.useRef(0);
|
|
185
|
+
// Ref (not state) because setActive() always accompanies updates, providing the re-render.
|
|
186
|
+
const lastUsedThumbIndexRef = React.useRef(-1);
|
|
187
|
+
// Prevents duplicate listener registration when both pointer and touch events fire
|
|
188
|
+
// for the same physical touch interaction.
|
|
189
|
+
const pointerDownHandledRef = React.useRef(false);
|
|
190
|
+
// Tracks which pointer owns the current drag session, so stray pointerup/pointermove
|
|
191
|
+
// events from a second pointer don't interfere.
|
|
192
|
+
const activePointerIdRef = React.useRef(-1);
|
|
205
193
|
const cancelFocusFrame = useEventCallback(() => {
|
|
206
|
-
if (
|
|
207
|
-
cancelAnimationFrame(
|
|
208
|
-
|
|
194
|
+
if (focusFrameRef.current != null) {
|
|
195
|
+
cancelAnimationFrame(focusFrameRef.current);
|
|
196
|
+
focusFrameRef.current = null;
|
|
209
197
|
}
|
|
210
198
|
});
|
|
211
|
-
//
|
|
212
|
-
const
|
|
199
|
+
// lastChangedValueRef is updated whenever onChange is triggered.
|
|
200
|
+
const lastChangedValueRef = React.useRef(null);
|
|
213
201
|
const [valueDerived, setValueState] = useControlled({
|
|
214
202
|
controlled: valueProp,
|
|
215
203
|
default: defaultValue ?? min,
|
|
216
204
|
name: 'Slider'
|
|
217
205
|
});
|
|
218
|
-
const handleChange =
|
|
206
|
+
const handleChange = useEventCallback((event, value, thumbIndex) => {
|
|
219
207
|
// Redefine target to allow name and value to be read.
|
|
220
208
|
// This allows seamless integration with the most popular form libraries.
|
|
221
209
|
// https://github.com/mui/material-ui/issues/13485#issuecomment-676048492
|
|
222
210
|
// Clone the event to not override `target` of the original event.
|
|
223
|
-
const nativeEvent = event.nativeEvent
|
|
224
|
-
// @ts-ignore The nativeEvent is function, not object
|
|
211
|
+
const nativeEvent = 'nativeEvent' in event ? event.nativeEvent : event;
|
|
225
212
|
const clonedEvent = new nativeEvent.constructor(nativeEvent.type, nativeEvent);
|
|
226
213
|
Object.defineProperty(clonedEvent, 'target', {
|
|
227
214
|
writable: true,
|
|
@@ -230,16 +217,43 @@ export function useSlider(parameters) {
|
|
|
230
217
|
name
|
|
231
218
|
}
|
|
232
219
|
});
|
|
233
|
-
|
|
234
|
-
onChange(clonedEvent, value, thumbIndex);
|
|
220
|
+
lastChangedValueRef.current = value;
|
|
221
|
+
onChange?.(clonedEvent, value, thumbIndex);
|
|
235
222
|
});
|
|
236
223
|
const range = Array.isArray(valueDerived);
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
224
|
+
const values = React.useMemo(() => {
|
|
225
|
+
if (typeof valueDerived === 'number') {
|
|
226
|
+
return [clamp(valueDerived, min, max)];
|
|
227
|
+
}
|
|
228
|
+
if (valueDerived == null) {
|
|
229
|
+
return [min];
|
|
230
|
+
}
|
|
231
|
+
const sortedValues = valueDerived.slice().sort(asc);
|
|
232
|
+
for (let i = 0; i < sortedValues.length; i += 1) {
|
|
233
|
+
const value = sortedValues[i];
|
|
234
|
+
sortedValues[i] = value == null ? min : clamp(value, min, max);
|
|
235
|
+
}
|
|
236
|
+
return sortedValues;
|
|
237
|
+
}, [valueDerived, min, max]);
|
|
238
|
+
const marks = React.useMemo(() => {
|
|
239
|
+
if (marksProp === true && step != null) {
|
|
240
|
+
const generatedMarks = new Array(Math.floor((max - min) / step) + 1);
|
|
241
|
+
for (let i = 0; i < generatedMarks.length; i += 1) {
|
|
242
|
+
generatedMarks[i] = {
|
|
243
|
+
value: min + step * i
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return generatedMarks;
|
|
247
|
+
}
|
|
248
|
+
return Array.isArray(marksProp) ? marksProp : EMPTY_MARKS;
|
|
249
|
+
}, [marksProp, step, min, max]);
|
|
250
|
+
const marksValues = React.useMemo(() => {
|
|
251
|
+
const markValues = new Array(marks.length);
|
|
252
|
+
for (let i = 0; i < marks.length; i += 1) {
|
|
253
|
+
markValues[i] = marks[i].value;
|
|
254
|
+
}
|
|
255
|
+
return markValues;
|
|
256
|
+
}, [marks]);
|
|
243
257
|
const [focusedThumbIndex, setFocusedThumbIndex] = React.useState(-1);
|
|
244
258
|
const sliderRef = React.useRef(null);
|
|
245
259
|
const handleRef = useForkRef(ref, sliderRef);
|
|
@@ -280,29 +294,22 @@ export function useSlider(parameters) {
|
|
|
280
294
|
newValue = clamp(newValue, values[index - 1] || -Infinity, values[index + 1] || Infinity);
|
|
281
295
|
}
|
|
282
296
|
const previousValue = newValue;
|
|
283
|
-
newValue = setValueIndex(
|
|
284
|
-
values,
|
|
285
|
-
newValue,
|
|
286
|
-
index
|
|
287
|
-
});
|
|
297
|
+
newValue = setValueIndex(values, newValue, index);
|
|
288
298
|
let activeIndex = index;
|
|
289
299
|
|
|
290
300
|
// Potentially swap the index if needed.
|
|
291
301
|
if (!disableSwap) {
|
|
292
302
|
activeIndex = newValue.indexOf(previousValue);
|
|
293
303
|
}
|
|
294
|
-
focusThumb(
|
|
295
|
-
sliderRef,
|
|
296
|
-
activeIndex
|
|
297
|
-
});
|
|
304
|
+
focusThumb(sliderRef, activeIndex);
|
|
298
305
|
}
|
|
299
306
|
setValueState(newValue);
|
|
300
307
|
setFocusedThumbIndex(index);
|
|
301
|
-
if (
|
|
308
|
+
if (onChange && !areValuesEqual(newValue, valueDerived)) {
|
|
302
309
|
handleChange(event, newValue, index);
|
|
303
310
|
}
|
|
304
311
|
if (onChangeCommitted) {
|
|
305
|
-
onChangeCommitted(event,
|
|
312
|
+
onChangeCommitted(event, lastChangedValueRef.current ?? newValue);
|
|
306
313
|
}
|
|
307
314
|
};
|
|
308
315
|
const createHandleHiddenInputKeyDown = otherHandlers => event => {
|
|
@@ -370,12 +377,14 @@ export function useSlider(parameters) {
|
|
|
370
377
|
otherHandlers?.onKeyDown?.(event);
|
|
371
378
|
};
|
|
372
379
|
useEnhancedEffect(() => {
|
|
373
|
-
|
|
380
|
+
const activeElement = getActiveElement(ownerDocument(sliderRef.current));
|
|
381
|
+
if (disabled && sliderRef.current?.contains(activeElement)) {
|
|
374
382
|
// This is necessary because Firefox and Safari will keep focus
|
|
375
383
|
// on a disabled element:
|
|
376
384
|
// https://codesandbox.io/p/sandbox/mui-pr-22247-forked-h151h?file=/src/App.js
|
|
377
|
-
|
|
378
|
-
|
|
385
|
+
if (activeElement != null && 'blur' in activeElement) {
|
|
386
|
+
activeElement.blur();
|
|
387
|
+
}
|
|
379
388
|
}
|
|
380
389
|
}, [disabled]);
|
|
381
390
|
if (disabled && active !== -1) {
|
|
@@ -386,22 +395,27 @@ export function useSlider(parameters) {
|
|
|
386
395
|
}
|
|
387
396
|
const createHandleHiddenInputChange = otherHandlers => event => {
|
|
388
397
|
otherHandlers.onChange?.(event);
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
changeValue(event, event.target.valueAsNumber);
|
|
398
|
+
// Handles value changes reported through the hidden range input.
|
|
399
|
+
changeValue(event, event.currentTarget.valueAsNumber);
|
|
392
400
|
};
|
|
393
|
-
const
|
|
401
|
+
const previousIndexRef = React.useRef(undefined);
|
|
394
402
|
let axis = orientation;
|
|
395
403
|
if (isRtl && orientation === 'horizontal') {
|
|
396
404
|
axis += '-reverse';
|
|
397
405
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
406
|
+
|
|
407
|
+
// Converts finger coordinates to a slider value and determines the active thumb.
|
|
408
|
+
// For range sliders, reads `previousIndexRef.current` to decide which thumb is active:
|
|
409
|
+
// -1 = initial press → find closest thumb
|
|
410
|
+
// ≥0 = drag in progress → keep same thumb
|
|
411
|
+
// Callers must reset `previousIndexRef.current = -1` before calling on a new interaction.
|
|
412
|
+
const getValueAtFinger = finger => {
|
|
402
413
|
const {
|
|
403
414
|
current: slider
|
|
404
415
|
} = sliderRef;
|
|
416
|
+
if (!slider) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
405
419
|
const {
|
|
406
420
|
width,
|
|
407
421
|
height,
|
|
@@ -428,27 +442,20 @@ export function useSlider(parameters) {
|
|
|
428
442
|
newValue = clamp(newValue, min, max);
|
|
429
443
|
let activeIndex = 0;
|
|
430
444
|
if (range) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
} else {
|
|
434
|
-
activeIndex = previousIndex.current;
|
|
435
|
-
}
|
|
445
|
+
const isDragging = previousIndexRef.current !== -1;
|
|
446
|
+
activeIndex = isDragging ? previousIndexRef.current : findClosest(values, newValue, lastUsedThumbIndexRef.current);
|
|
436
447
|
|
|
437
448
|
// Bound the new value to the thumb's neighbours.
|
|
438
449
|
if (disableSwap) {
|
|
439
450
|
newValue = clamp(newValue, values[activeIndex - 1] || -Infinity, values[activeIndex + 1] || Infinity);
|
|
440
451
|
}
|
|
441
452
|
const previousValue = newValue;
|
|
442
|
-
newValue = setValueIndex(
|
|
443
|
-
values,
|
|
444
|
-
newValue,
|
|
445
|
-
index: activeIndex
|
|
446
|
-
});
|
|
453
|
+
newValue = setValueIndex(values, newValue, activeIndex);
|
|
447
454
|
|
|
448
455
|
// Potentially swap the index if needed.
|
|
449
|
-
if (!(disableSwap &&
|
|
456
|
+
if (!(disableSwap && isDragging)) {
|
|
450
457
|
activeIndex = newValue.indexOf(previousValue);
|
|
451
|
-
|
|
458
|
+
previousIndexRef.current = activeIndex;
|
|
452
459
|
}
|
|
453
460
|
}
|
|
454
461
|
return {
|
|
@@ -457,60 +464,61 @@ export function useSlider(parameters) {
|
|
|
457
464
|
};
|
|
458
465
|
};
|
|
459
466
|
const handleTouchMove = useEventCallback(nativeEvent => {
|
|
460
|
-
|
|
467
|
+
// Ignore pointer events from a different pointer than the one that started the drag.
|
|
468
|
+
if ('pointerId' in nativeEvent && nativeEvent.pointerId !== activePointerIdRef.current) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const finger = trackFinger(nativeEvent, touchIdRef);
|
|
461
472
|
if (!finger) {
|
|
462
473
|
return;
|
|
463
474
|
}
|
|
464
|
-
|
|
475
|
+
moveCountRef.current += 1;
|
|
465
476
|
|
|
466
|
-
// Cancel move in case some other element consumed a
|
|
467
|
-
|
|
468
|
-
if (nativeEvent.type === 'mousemove' && nativeEvent.buttons === 0) {
|
|
477
|
+
// Cancel move in case some other element consumed a pointerup event and it was not fired.
|
|
478
|
+
if (nativeEvent.type === 'pointermove' && nativeEvent.buttons === 0) {
|
|
469
479
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
470
480
|
handleTouchEnd(nativeEvent);
|
|
471
481
|
return;
|
|
472
482
|
}
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
sliderRef,
|
|
482
|
-
activeIndex,
|
|
483
|
-
setActive,
|
|
484
|
-
focusVisible: false
|
|
485
|
-
});
|
|
486
|
-
setValueState(newValue);
|
|
487
|
-
if (!dragging && moveCount.current > INTENTIONAL_DRAG_COUNT_THRESHOLD) {
|
|
483
|
+
const newFingerValue = getValueAtFinger(finger);
|
|
484
|
+
if (!newFingerValue) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
focusThumb(sliderRef, newFingerValue.activeIndex, setActive, false);
|
|
488
|
+
lastUsedThumbIndexRef.current = newFingerValue.activeIndex;
|
|
489
|
+
setValueState(newFingerValue.newValue);
|
|
490
|
+
if (!dragging && moveCountRef.current > INTENTIONAL_DRAG_COUNT_THRESHOLD) {
|
|
488
491
|
setDragging(true);
|
|
489
492
|
}
|
|
490
|
-
if (
|
|
491
|
-
handleChange(nativeEvent, newValue, activeIndex);
|
|
493
|
+
if (onChange && !areValuesEqual(newFingerValue.newValue, valueDerived)) {
|
|
494
|
+
handleChange(nativeEvent, newFingerValue.newValue, newFingerValue.activeIndex);
|
|
492
495
|
}
|
|
493
496
|
});
|
|
494
497
|
const handleTouchEnd = useEventCallback(nativeEvent => {
|
|
495
|
-
|
|
498
|
+
// Ignore pointer events from a different pointer than the one that started the drag.
|
|
499
|
+
if ('pointerId' in nativeEvent && nativeEvent.pointerId !== activePointerIdRef.current) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const finger = trackFinger(nativeEvent, touchIdRef);
|
|
496
503
|
setDragging(false);
|
|
497
504
|
if (!finger) {
|
|
498
505
|
return;
|
|
499
506
|
}
|
|
500
|
-
const
|
|
501
|
-
newValue
|
|
502
|
-
} = getFingerNewValue({
|
|
503
|
-
finger,
|
|
504
|
-
move: true
|
|
505
|
-
});
|
|
507
|
+
const newFingerValue = getValueAtFinger(finger);
|
|
506
508
|
setActive(-1);
|
|
507
509
|
if (nativeEvent.type === 'touchend') {
|
|
508
510
|
setOpen(-1);
|
|
509
511
|
}
|
|
510
|
-
if (onChangeCommitted) {
|
|
511
|
-
onChangeCommitted(nativeEvent,
|
|
512
|
+
if (newFingerValue && onChangeCommitted) {
|
|
513
|
+
onChangeCommitted(nativeEvent, lastChangedValueRef.current ?? newFingerValue.newValue);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Release pointer capture if applicable
|
|
517
|
+
if ('pointerType' in nativeEvent && sliderRef.current?.hasPointerCapture(nativeEvent.pointerId)) {
|
|
518
|
+
sliderRef.current.releasePointerCapture(nativeEvent.pointerId);
|
|
512
519
|
}
|
|
513
|
-
|
|
520
|
+
touchIdRef.current = undefined;
|
|
521
|
+
activePointerIdRef.current = -1;
|
|
514
522
|
|
|
515
523
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
516
524
|
stopListening();
|
|
@@ -519,35 +527,36 @@ export function useSlider(parameters) {
|
|
|
519
527
|
if (disabled) {
|
|
520
528
|
return;
|
|
521
529
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
530
|
+
|
|
531
|
+
// If the pointer path already handled this interaction,
|
|
532
|
+
// only record the touch identifier and skip duplicate listener registration.
|
|
533
|
+
if (pointerDownHandledRef.current) {
|
|
534
|
+
pointerDownHandledRef.current = false;
|
|
535
|
+
const touch = nativeEvent.changedTouches[0];
|
|
536
|
+
if (touch != null) {
|
|
537
|
+
touchIdRef.current = touch.identifier;
|
|
538
|
+
}
|
|
539
|
+
return;
|
|
525
540
|
}
|
|
526
541
|
const touch = nativeEvent.changedTouches[0];
|
|
527
542
|
if (touch != null) {
|
|
528
543
|
// A number that uniquely identifies the current finger in the touch session.
|
|
529
|
-
|
|
544
|
+
touchIdRef.current = touch.identifier;
|
|
530
545
|
}
|
|
531
|
-
const finger = trackFinger(nativeEvent,
|
|
546
|
+
const finger = trackFinger(nativeEvent, touchIdRef);
|
|
532
547
|
if (finger !== false) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
setActive,
|
|
543
|
-
focusVisible: false
|
|
544
|
-
});
|
|
545
|
-
setValueState(newValue);
|
|
546
|
-
if (handleChange && !areValuesEqual(newValue, valueDerived)) {
|
|
547
|
-
handleChange(nativeEvent, newValue, activeIndex);
|
|
548
|
+
previousIndexRef.current = -1;
|
|
549
|
+
const newFingerValue = getValueAtFinger(finger);
|
|
550
|
+
if (newFingerValue) {
|
|
551
|
+
focusThumb(sliderRef, newFingerValue.activeIndex, setActive, false);
|
|
552
|
+
lastUsedThumbIndexRef.current = newFingerValue.activeIndex;
|
|
553
|
+
setValueState(newFingerValue.newValue);
|
|
554
|
+
if (onChange && !areValuesEqual(newFingerValue.newValue, valueDerived)) {
|
|
555
|
+
handleChange(nativeEvent, newFingerValue.newValue, newFingerValue.activeIndex);
|
|
556
|
+
}
|
|
548
557
|
}
|
|
549
558
|
}
|
|
550
|
-
|
|
559
|
+
moveCountRef.current = 0;
|
|
551
560
|
const doc = ownerDocument(sliderRef.current);
|
|
552
561
|
doc.addEventListener('touchmove', handleTouchMove, {
|
|
553
562
|
passive: true
|
|
@@ -558,17 +567,18 @@ export function useSlider(parameters) {
|
|
|
558
567
|
});
|
|
559
568
|
const stopListening = React.useCallback(() => {
|
|
560
569
|
const doc = ownerDocument(sliderRef.current);
|
|
561
|
-
doc.removeEventListener('
|
|
562
|
-
doc.removeEventListener('
|
|
570
|
+
doc.removeEventListener('pointermove', handleTouchMove);
|
|
571
|
+
doc.removeEventListener('pointerup', handleTouchEnd);
|
|
563
572
|
doc.removeEventListener('touchmove', handleTouchMove);
|
|
564
573
|
doc.removeEventListener('touchend', handleTouchEnd);
|
|
565
574
|
}, [handleTouchEnd, handleTouchMove]);
|
|
566
575
|
React.useEffect(() => {
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
576
|
+
const slider = sliderRef.current;
|
|
577
|
+
if (!slider) {
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
570
580
|
slider.addEventListener('touchstart', handleTouchStart, {
|
|
571
|
-
passive:
|
|
581
|
+
passive: true
|
|
572
582
|
});
|
|
573
583
|
return () => {
|
|
574
584
|
slider.removeEventListener('touchstart', handleTouchStart);
|
|
@@ -582,62 +592,67 @@ export function useSlider(parameters) {
|
|
|
582
592
|
cancelFocusFrame();
|
|
583
593
|
}
|
|
584
594
|
}, [disabled, stopListening, cancelFocusFrame]);
|
|
585
|
-
const
|
|
586
|
-
otherHandlers.
|
|
587
|
-
if (disabled) {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
if (event.defaultPrevented) {
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
595
|
+
const createHandlePointerDown = otherHandlers => event => {
|
|
596
|
+
otherHandlers.onPointerDown?.(event);
|
|
593
597
|
|
|
594
|
-
//
|
|
595
|
-
|
|
598
|
+
// On touch devices, the browser fires both pointerdown and touchstart for the
|
|
599
|
+
// same physical touch. Mark this BEFORE early returns so handleTouchStart always
|
|
600
|
+
// knows the pointer path saw this interaction — even if it was prevented or disabled.
|
|
601
|
+
if (event.pointerType === 'touch') {
|
|
602
|
+
pointerDownHandledRef.current = true;
|
|
603
|
+
}
|
|
604
|
+
if (disabled || event.defaultPrevented || event.button !== 0) {
|
|
596
605
|
return;
|
|
597
606
|
}
|
|
598
|
-
const finger = trackFinger(event,
|
|
607
|
+
const finger = trackFinger(event, touchIdRef);
|
|
599
608
|
if (finger !== false) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
focusFrame.current = null;
|
|
616
|
-
focusThumb({
|
|
617
|
-
sliderRef,
|
|
618
|
-
activeIndex,
|
|
619
|
-
focusVisible: false
|
|
609
|
+
previousIndexRef.current = -1;
|
|
610
|
+
const newFingerValue = getValueAtFinger(finger);
|
|
611
|
+
if (newFingerValue) {
|
|
612
|
+
const thumbInput = sliderRef.current?.querySelector(`input[type="range"][data-index="${newFingerValue.activeIndex}"]`);
|
|
613
|
+
const doc = ownerDocument(sliderRef.current);
|
|
614
|
+
const pressedOnFocusedThumb = thumbInput != null && thumbInput === getActiveElement(doc);
|
|
615
|
+
setActive(newFingerValue.activeIndex);
|
|
616
|
+
lastUsedThumbIndexRef.current = newFingerValue.activeIndex;
|
|
617
|
+
if (pressedOnFocusedThumb) {
|
|
618
|
+
event.preventDefault();
|
|
619
|
+
} else {
|
|
620
|
+
cancelFocusFrame();
|
|
621
|
+
focusFrameRef.current = requestAnimationFrame(() => {
|
|
622
|
+
focusFrameRef.current = null;
|
|
623
|
+
focusThumb(sliderRef, newFingerValue.activeIndex, undefined, false);
|
|
620
624
|
});
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
625
|
+
}
|
|
626
|
+
setValueState(newFingerValue.newValue);
|
|
627
|
+
if (onChange && !areValuesEqual(newFingerValue.newValue, valueDerived)) {
|
|
628
|
+
handleChange(event, newFingerValue.newValue, newFingerValue.activeIndex);
|
|
629
|
+
}
|
|
626
630
|
}
|
|
627
631
|
}
|
|
628
|
-
|
|
632
|
+
moveCountRef.current = 0;
|
|
633
|
+
activePointerIdRef.current = event.pointerId;
|
|
629
634
|
const doc = ownerDocument(sliderRef.current);
|
|
630
|
-
|
|
635
|
+
|
|
636
|
+
// Use pointer capture for reliable drag tracking
|
|
637
|
+
try {
|
|
638
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
639
|
+
} catch {
|
|
640
|
+
// setPointerCapture can throw if the pointerId is invalid (e.g. synthetic
|
|
641
|
+
// events in tests, or the pointer was already released). The slider still
|
|
642
|
+
// works via document-level listeners; pointer capture is a progressive
|
|
643
|
+
// enhancement for reliable drag tracking.
|
|
644
|
+
}
|
|
645
|
+
doc.addEventListener('pointermove', handleTouchMove, {
|
|
631
646
|
passive: true
|
|
632
647
|
});
|
|
633
|
-
doc.addEventListener('
|
|
648
|
+
doc.addEventListener('pointerup', handleTouchEnd);
|
|
634
649
|
};
|
|
635
650
|
const trackOffset = valueToPercent(range ? values[0] : min, min, max);
|
|
636
651
|
const trackLeap = valueToPercent(values[values.length - 1], min, max) - trackOffset;
|
|
637
|
-
const getRootProps = (externalProps =
|
|
652
|
+
const getRootProps = (externalProps = EMPTY_OBJ) => {
|
|
638
653
|
const externalHandlers = extractEventHandlers(externalProps);
|
|
639
654
|
const ownEventHandlers = {
|
|
640
|
-
|
|
655
|
+
onPointerDown: createHandlePointerDown(externalHandlers)
|
|
641
656
|
};
|
|
642
657
|
const mergedEventHandlers = {
|
|
643
658
|
...externalHandlers,
|
|
@@ -658,11 +673,11 @@ export function useSlider(parameters) {
|
|
|
658
673
|
otherHandlers.onMouseLeave?.(event);
|
|
659
674
|
setOpen(-1);
|
|
660
675
|
};
|
|
661
|
-
const getThumbProps = (externalProps =
|
|
676
|
+
const getThumbProps = (externalProps = EMPTY_OBJ) => {
|
|
662
677
|
const externalHandlers = extractEventHandlers(externalProps);
|
|
663
678
|
const ownEventHandlers = {
|
|
664
|
-
onMouseOver: createHandleMouseOver(externalHandlers
|
|
665
|
-
onMouseLeave: createHandleMouseLeave(externalHandlers
|
|
679
|
+
onMouseOver: createHandleMouseOver(externalHandlers),
|
|
680
|
+
onMouseLeave: createHandleMouseLeave(externalHandlers)
|
|
666
681
|
};
|
|
667
682
|
return {
|
|
668
683
|
...externalProps,
|
|
@@ -671,22 +686,33 @@ export function useSlider(parameters) {
|
|
|
671
686
|
};
|
|
672
687
|
};
|
|
673
688
|
const getThumbStyle = index => {
|
|
689
|
+
let zIndex;
|
|
690
|
+
if (range) {
|
|
691
|
+
if (active === index) {
|
|
692
|
+
zIndex = 2;
|
|
693
|
+
} else if (lastUsedThumbIndexRef.current === index) {
|
|
694
|
+
zIndex = 1;
|
|
695
|
+
}
|
|
696
|
+
} else if (active === index) {
|
|
697
|
+
zIndex = 1;
|
|
698
|
+
}
|
|
674
699
|
return {
|
|
675
700
|
// So the non active thumb doesn't show its label on hover.
|
|
676
|
-
pointerEvents: active !== -1 && active !== index ? 'none' : undefined
|
|
701
|
+
pointerEvents: active !== -1 && active !== index ? 'none' : undefined,
|
|
702
|
+
zIndex
|
|
677
703
|
};
|
|
678
704
|
};
|
|
679
705
|
let cssWritingMode;
|
|
680
706
|
if (orientation === 'vertical') {
|
|
681
707
|
cssWritingMode = isRtl ? 'vertical-rl' : 'vertical-lr';
|
|
682
708
|
}
|
|
683
|
-
const getHiddenInputProps = (externalProps =
|
|
709
|
+
const getHiddenInputProps = (externalProps = EMPTY_OBJ) => {
|
|
684
710
|
const externalHandlers = extractEventHandlers(externalProps);
|
|
685
711
|
const ownEventHandlers = {
|
|
686
|
-
onChange: createHandleHiddenInputChange(externalHandlers
|
|
687
|
-
onFocus: createHandleHiddenInputFocus(externalHandlers
|
|
688
|
-
onBlur: createHandleHiddenInputBlur(externalHandlers
|
|
689
|
-
onKeyDown: createHandleHiddenInputKeyDown(externalHandlers
|
|
712
|
+
onChange: createHandleHiddenInputChange(externalHandlers),
|
|
713
|
+
onFocus: createHandleHiddenInputFocus(externalHandlers),
|
|
714
|
+
onBlur: createHandleHiddenInputBlur(externalHandlers),
|
|
715
|
+
onKeyDown: createHandleHiddenInputKeyDown(externalHandlers)
|
|
690
716
|
};
|
|
691
717
|
const mergedEventHandlers = {
|
|
692
718
|
...externalHandlers,
|
|
@@ -725,7 +751,7 @@ export function useSlider(parameters) {
|
|
|
725
751
|
getHiddenInputProps,
|
|
726
752
|
getRootProps,
|
|
727
753
|
getThumbProps,
|
|
728
|
-
marks
|
|
754
|
+
marks,
|
|
729
755
|
open,
|
|
730
756
|
range,
|
|
731
757
|
rootRef: handleRef,
|