滑桿API
React 滑桿元件的 API 參考文件。了解這個匯出模組的 props、CSS 和其他 API。
示範
匯入
import Slider from '@mui/material/Slider';
// or
import { Slider } from '@mui/material';
閱讀這份關於最小化 bundle 大小的指南,以了解差異。
原生元件的 Props 也可用。
名稱 | 類型 | 預設 | 描述 |
---|---|---|---|
aria-label | string | - | 滑桿的標籤。 |
aria-labelledby | string | - | 包含滑桿標籤之元素的 ID。 |
aria-valuetext | string | - | 一個字串值,為滑桿的目前值提供使用者友善的名稱。 |
classes | object | - | 覆寫或擴展套用至元件的樣式。 請參閱下方CSS 類別 API 以了解更多詳細資訊。 |
color | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string | 'primary' | 元件的顏色。它同時支援預設和自訂主題顏色,這些顏色可以如調色盤自訂指南中所示新增。 |
components | { Input?: elementType, Mark?: elementType, MarkLabel?: elementType, Rail?: elementType, Root?: elementType, Thumb?: elementType, Track?: elementType, ValueLabel?: elementType } | {} | 用於每個 slot 內部的元件。 |
componentsProps | { input?: func | object, mark?: func | object, markLabel?: func | object, rail?: func | object, root?: func | object, thumb?: func | object, track?: func | object, valueLabel?: func | { children?: element, className?: string, open?: bool, style?: object, value?: node, valueLabelDisplay?: 'auto' | 'off' | 'on' } } | {} | slot 元件的額外 props。您可以覆寫現有的 props 或新增 props。 |
defaultValue | Array<number> | number | - | 預設值。當元件不受控制時使用。 |
disabled | bool | false | 如果為 |
disableSwap | bool | false | 如果為 |
getAriaLabel | func | - | 接受一個函式,該函式傳回一個字串值,為滑桿的滑桿標籤提供使用者友善的名稱。這對於螢幕閱讀器使用者來說很重要。 簽名: function(index: number) => string
|
getAriaValueText | func | - | 接受一個函式,該函式傳回一個字串值,為滑桿的目前值提供使用者友善的名稱。這對於螢幕閱讀器使用者來說很重要。 簽名: function(value: number, index: number) => string
|
marks | Array<{ label?: node, value: number }> | bool | false | 刻度標記指示使用者可以將滑桿移動到的預定值。如果為 |
max | number | 100 | 滑桿允許的最大值。不應等於 min。 |
min | number | 0 | 滑桿允許的最小值。不應等於 max。 |
name | string | - | 隱藏 |
onChange | func | - | 當滑桿的值變更時觸發的回呼函式。 簽名: function(event: Event, value: Value, activeThumb: number) => void
|
onChangeCommitted | func | - | 當觸發 簽名: function(event: React.SyntheticEvent | Event, value: Value) => void
|
orientation | 'horizontal' | 'vertical' | 'horizontal' | 元件方向。 |
scale | func | function Identity(x) { return x; } | 轉換函式,用於變更滑桿的比例。 簽名: function(x: any) => any |
shiftStep | number | 10 | 當使用 Page Up/Page Down 或 Shift + 向上/向下箭頭時,滑桿可以逐步瀏覽值的精細度。 |
size | 'small' | 'medium' | string | 'medium' | 滑桿的大小。 |
slotProps | { input?: func | object, mark?: func | object, markLabel?: func | object, rail?: func | object, root?: func | object, thumb?: func | object, track?: func | object, valueLabel?: func | { children?: element, className?: string, open?: bool, style?: object, value?: node, valueLabelDisplay?: 'auto' | 'off' | 'on' } } | {} | 用於滑桿內部每個 slot 的 props。 |
slots | { input?: elementType, mark?: elementType, markLabel?: elementType, rail?: elementType, root?: elementType, thumb?: elementType, track?: elementType, valueLabel?: elementType } | {} | 用於滑桿內部每個 slot 的元件。字串可使用 HTML 元素或元件。 |
step | number | 1 | 滑桿可以逐步瀏覽值的精細度。(「離散」滑桿。) |
sx | Array<func | object | bool> | func | object | - | 系統 prop,允許定義系統覆寫以及其他 CSS 樣式。 請參閱 `sx` 頁面 以了解更多詳細資訊。 |
tabIndex | number | - | 隱藏 |
track | 'inverted' | 'normal' | false | 'normal' | 軌跡呈現方式
|
value | Array<number> | number | - | 滑桿的值。對於範圍滑桿,請提供包含兩個值的陣列。 |
valueLabelDisplay | 'auto' | 'off' | 'on' | 'off' | 控制何時顯示值標籤
|
valueLabelFormat | func | string | function Identity(x) { return x; } | 格式化值標籤值的格式化函式。 |
ref
會轉發到根元素。主題預設 props
您可以使用 MuiSlider
透過主題變更此元件的預設 props。
這些類別名稱對於使用 CSS 設定樣式很有用。當觸發特定狀態時,它們會套用至元件的 slots。
類別名稱 | 規則名稱 | 描述 |
---|---|---|
.Mui-active | 如果滑桿元素處於作用中狀態,則套用至滑桿元素的狀態類別。 | |
.Mui-disabled | 如果 disabled={true} ,則套用至根元素和滑桿元素的狀態類別。 | |
.Mui-focusVisible | 如果鍵盤聚焦,則套用至滑桿元素的狀態類別。 | |
.MuiSlider-colorError | colorError | 如果 color="error" ,則套用至根元素的樣式。 |
.MuiSlider-colorInfo | colorInfo | 如果 color="info" ,則套用至根元素的樣式。 |
.MuiSlider-colorPrimary | colorPrimary | 如果 color="primary" ,則套用至根元素的樣式。 |
.MuiSlider-colorSecondary | colorSecondary | 如果 color="secondary" ,則套用至根元素的樣式。 |
.MuiSlider-colorSuccess | colorSuccess | 如果 color="success" ,則套用至根元素的樣式。 |
.MuiSlider-colorWarning | colorWarning | 如果 color="warning" ,則套用至根元素的樣式。 |
.MuiSlider-dragging | dragging | 如果正在拖曳滑桿,則套用至根元素的狀態類別。 |
.MuiSlider-mark | mark | 套用至刻度標記元素的樣式。 |
.MuiSlider-markActive | markActive | 如果處於作用中狀態(取決於值),則套用至刻度標記元素的樣式。 |
.MuiSlider-marked | marked | 如果 marks 提供至少一個標籤,則套用至根元素的樣式。 |
.MuiSlider-markLabel | markLabel | 套用至刻度標記標籤元素的樣式。 |
.MuiSlider-markLabelActive | markLabelActive | 如果處於作用中狀態(取決於值),則套用至刻度標記標籤元素的樣式。 |
.MuiSlider-rail | rail | 套用至軌跡元素的樣式。 |
.MuiSlider-root | root | 套用至根元素的樣式。 |
.MuiSlider-sizeSmall | sizeSmall | 如果 size="small" ,則套用至根元素的樣式。 |
.MuiSlider-thumb | thumb | 套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorError | thumbColorError | 如果 color="error" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorInfo | thumbColorInfo | 如果 color="info" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorPrimary | thumbColorPrimary | 如果 color="primary" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorSecondary | thumbColorSecondary | 如果 color="secondary" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorSuccess | thumbColorSuccess | 如果 color="success" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbColorWarning | thumbColorWarning | 如果 color="warning" ,則套用至滑桿元素的樣式。 |
.MuiSlider-thumbSizeSmall | thumbSizeSmall | 如果 size="small" ,則套用至滑桿元素的樣式。 |
.MuiSlider-track | track | 套用至軌跡元素的樣式。 |
.MuiSlider-trackFalse | trackFalse | 如果 track={false} ,則套用至根元素的樣式。 |
.MuiSlider-trackInverted | trackInverted | 如果 track="inverted" ,則套用至根元素的樣式。 |
.MuiSlider-valueLabel | valueLabel | 套用至滑桿標籤元素的樣式。 |
.MuiSlider-valueLabelCircle | valueLabelCircle | 套用至滑桿標籤圓形元素的樣式。 |
.MuiSlider-valueLabelLabel | valueLabelLabel | 套用至滑桿標籤標籤元素的樣式。 |
.MuiSlider-valueLabelOpen | valueLabelOpen | 如果滑桿標籤元素處於開啟狀態,則套用至滑桿標籤元素的樣式。 |
.MuiSlider-vertical | vertical | 如果 orientation="vertical" ,則套用至根元素的樣式。 |
您可以使用以下自訂選項之一覆寫元件的樣式
- 使用全域類別名稱。
- 在自訂主題中,使用規則名稱作為元件的
styleOverrides
屬性的一部分。
原始碼
如果您在此頁面中找不到資訊,請考慮查看元件的實作程式碼以取得更多詳細資訊。