Slider 滑块控件
用户可以使用滑块控件在某一范围内取值。
滑块反映了一根条上的一系列值,用户可以从中选择单个值。 它们通常适用于调节一些设置,譬如调节设备音量、调整屏幕亮度,或者改变图像的滤镜。
Minimum distance
You can enforce a minimum distance between values in the onChange
event handler. By default, when you move the pointer over a thumb while dragging another thumb, the active thumb will swap to the hovered thumb. You can disable this behavior with the disableSwap
prop. You can enforce a minimum distance between values in the onChange
event handler. By default, when you move the pointer over a thumb while dragging another thumb, the active thumb will swap to the hovered thumb. You can disable this behavior with the disableSwap
prop. You can enforce a minimum distance between values in the onChange
event handler. By default, when you move the pointer over a thumb while dragging another thumb, the active thumb will swap to the hovered thumb. You can disable this behavior with the disableSwap
prop. If you want the range to shift when reaching minimum distance, you can utilize the activeThumb
parameter in onChange
.
Volume
自定义滑块
你可以参考以下一些例子来自定义组件。 You can learn more about this in the overrides documentation page.
iOS
pretto.fr
Tooltip value label
Airbnb
คนเก่าเขาทำไว้ดี (Can't win)
Chilling Sunday — คนเก่าเขาทำไว้ดี
0:32
-2:48
警告: Chrome、Safari 和较新的 Edge 版本,即任何基于 WebKit 的浏览器都会将 <Slider orientation="vertical" />
暴露为水平状态(chromium 问题 #1158217)。 通过应用 -webkit-appearance: slider-vertical;
将滑块显示为垂直。
然而,应用 -webkit-appearance: slider-vertical;
之后会导致水平键的键盘导航(向左箭头,向右箭头)被反转(chromium 问题 #1162640)。 通常情况下,向上、向右应增加,向左、向下应减少数值。 如果你应用 -webkit-appearance
,那么就可以阻止键盘导航水平方向键的功能,以实现真正的垂直滑块。 与改变方向相比,这可能会减少用户的困惑。
Removed track
Removed track range slider
Inverted track
Inverted track range
Storage: 1 MB
Accessibility
(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/slidertwothumb/)
The component handles most of the work necessary to make it accessible. However, you need to make sure that:
- Each thumb has a user-friendly label (
aria-label
,aria-labelledby
orgetAriaLabel
prop). - Each thumb has a user-friendly text for its current value. This is not required if the value matches the semantics of the label. You can change the name with the
getAriaValueText
oraria-valuetext
prop.
Limitations
IE 11
The slider's value label is not centered in IE 11. The alignement is not handled to make customizations easier with the lastest browsers. You can solve the issue with:
.MuiSlider-valueLabel {
left: calc(-50% - 4px);
}