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

fix(VSwitch): render in forced-colors mode #19703

Merged
merged 6 commits into from May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/vuetify/src/components/VSwitch/VSwitch.sass
Expand Up @@ -134,3 +134,58 @@

.v-selection-control__wrapper
transform: $switch-thumb-vertical-transform

@media (forced-colors: active)
.v-switch
.v-switch__loader
.v-progress-circular
color: currentColor

.v-switch__thumb
background-color: buttontext

.v-switch__track,
.v-switch__thumb
border: 1px solid
color: buttontext

&:not(.v-switch--loading):not(.v-input--disabled)
.v-selection-control--dirty
.v-switch__thumb
background-color: highlight

&:not(.v-input--disabled)
.v-selection-control--dirty
.v-switch__track
background-color: highlight

.v-switch__track,
.v-switch__thumb
color: highlight

&.v-switch--inset
.v-switch__track
border-width: 2px

&:not(.v-switch--loading):not(.v-input--disabled)
.v-selection-control--dirty
.v-switch__thumb
background-color: highlighttext
color: highlighttext

&.v-input--disabled
.v-switch__thumb
background-color: graytext

.v-switch__track,
.v-switch__thumb
color: graytext

&.v-switch--loading
.v-switch__thumb
background-color: canvas

&.v-switch--inset,
&.v-switch--indeterminate
.v-switch__thumb
border-width: 0
7 changes: 4 additions & 3 deletions packages/vuetify/src/components/VSwitch/VSwitch.tsx
Expand Up @@ -16,7 +16,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, ref } from 'vue'
import { filterInputAttrs, genericComponent, getUid, propsFactory, useRender } from '@/util'
import { filterInputAttrs, genericComponent, getUid, IN_BROWSER, propsFactory, useRender } from '@/util'

// Types
import type { ComputedRef, Ref } from 'vue'
Expand Down Expand Up @@ -79,6 +79,7 @@ export const VSwitch = genericComponent<new <T>(
const { loaderClasses } = useLoader(props)
const { isFocused, focus, blur } = useFocus(props)
const control = ref<VSelectionControl>()
const isForcedColorsModeActive = IN_BROWSER && window.matchMedia('(forced-colors: active)').matches

const loaderColor = computed(() => {
return typeof props.loading === 'string' && props.loading !== ''
Expand Down Expand Up @@ -158,7 +159,7 @@ export const VSwitch = genericComponent<new <T>(
<div
class={[
'v-switch__track',
...backgroundColorClasses.value,
...(!isForcedColorsModeActive ? backgroundColorClasses.value : ''),
06b marked this conversation as resolved.
Show resolved Hide resolved
]}
style={ backgroundColorStyles.value }
onClick={ onTrackClick }
Expand All @@ -183,7 +184,7 @@ export const VSwitch = genericComponent<new <T>(
class={[
'v-switch__thumb',
{ 'v-switch__thumb--filled': icon || props.loading },
props.inset ? undefined : backgroundColorClasses.value,
props.inset || isForcedColorsModeActive ? undefined : backgroundColorClasses.value,
]}
style={ props.inset ? undefined : backgroundColorStyles.value }
>
Expand Down