Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(VSlider): introduce track disabled #20874

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/api-generator/src/locale/en/VSlider.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"props": {
"alwaysDirty": "When used with the **thumb-label** prop will always show the thumb label.",
"inverseLabel": "Reverse the label position. Works with **rtl**.",
"vertical": "Changes slider direction to vertical."
"vertical": "Changes slider direction to vertical.",
"trackDisabled": "Disables clicking on the slider track"
},
"slots": {
"thumb-label": "Slot for the thumb label.",
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/src/examples/v-slider/prop-track-disabled.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<v-slider
model-value="30"
track-disabled
></v-slider>
</template>
7 changes: 7 additions & 0 deletions packages/vuetify/src/components/VSlider/VSlider.sass
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@
.v-input--disabled &
opacity: var(--v-disabled-opacity)

.v-slider--track-disabled &
cursor: default

.v-input--error:not(.v-input--disabled) &
color: rgb(var(--v-theme-error))

.v-slider-thumb
.v-slider--track-disabled &
cursor: pointer

// Modifiers
.v-slider.v-input--horizontal
align-items: center
Expand Down
1 change: 1 addition & 0 deletions packages/vuetify/src/components/VSlider/VSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const VSlider = genericComponent<VSliderSlots>()({
'v-slider--focused': isFocused.value,
'v-slider--pressed': mousePressed.value,
'v-slider--disabled': props.disabled,
'v-slider--track-disabled': props.trackDisabled,
},
rtlClasses.value,
props.class,
Expand Down
9 changes: 9 additions & 0 deletions packages/vuetify/src/components/VSlider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export const makeSliderProps = propsFactory({
type: [Number, String],
default: 4,
},
trackDisabled: {
type: Boolean as PropType<boolean | null>,
default: null,
},
direction: {
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
Expand Down Expand Up @@ -194,6 +198,7 @@ export const useSlider = ({
const trackSize = computed(() => parseInt(props.trackSize, 10))
const numTicks = computed(() => (max.value - min.value) / step.value)
const disabled = toRef(props, 'disabled')
const trackDisabled = toRef(props, 'trackDisabled')

const thumbColor = computed(() => props.error || props.disabled ? undefined : props.thumbColor ?? props.color)
const trackColor = computed(() => props.error || props.disabled ? undefined : props.trackColor ?? props.color)
Expand Down Expand Up @@ -283,6 +288,10 @@ export const useSlider = ({
function onSliderMousedown (e: MouseEvent) {
e.preventDefault()

if (trackDisabled.value && !(e.target as HTMLElement).closest('.v-slider-thumb')) {
return
}

handleStart(e)

window.addEventListener('mousemove', onMouseMove, moveListenerOptions)
Expand Down