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(VListItem): properly display active-color when active #13912

Merged
merged 2 commits into from
Jul 10, 2021
Merged
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
14 changes: 7 additions & 7 deletions packages/vuetify/src/components/VAlert/VAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'
import { useTextColor } from '@/composables/color'

// Utilities
import { computed, reactive, toRef } from 'vue'
import { computed } from 'vue'
import { defineComponent } from '@/util'

// Types
Expand Down Expand Up @@ -94,11 +94,11 @@ export default defineComponent({

return props.icon ?? `$${props.type}`
})
const variantProps = reactive({
color: computed(() => (props.color ?? props.type)),
textColor: toRef(props, 'textColor'),
variant: toRef(props, 'variant'),
})
const variantProps = computed(() => ({
color: props.color ?? props.type,
textColor: props.textColor,
variant: props.variant,
}))

const { themeClasses } = useTheme(props)
const { borderClasses } = useBorder(borderProps.value, 'v-alert')
Expand All @@ -108,7 +108,7 @@ export default defineComponent({
const { positionClasses, positionStyles } = usePosition(props, 'v-alert')
const { roundedClasses } = useRounded(props, 'v-alert')
const { textColorClasses, textColorStyles } = useTextColor(computed(() => {
return props.borderColor ?? (props.tip ? variantProps.color : undefined)
return props.borderColor ?? (props.tip ? variantProps.value.color : undefined)
}))

function onCloseClick (e: MouseEvent) {
Expand Down
12 changes: 6 additions & 6 deletions packages/vuetify/src/components/VList/VListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { genOverlays, makeVariantProps, useVariant } from '@/composables/variant
import { Ripple } from '@/directives/ripple'

// Utilities
import { computed, reactive, toRef } from 'vue'
import { computed } from 'vue'
import { defineComponent } from '@/util'

export default defineComponent({
Expand Down Expand Up @@ -61,11 +61,11 @@ export default defineComponent({
return props.active || link.isExactActive?.value
})
const activeColor = props.activeColor ?? props.color
const variantProps = reactive({
color: computed(() => (isActive.value ? activeColor : props.color)),
textColor: toRef(props, 'textColor'),
variant: toRef(props, 'variant'),
})
const variantProps = computed(() => ({
color: isActive.value ? activeColor : props.color,
textColor: props.textColor,
variant: props.variant,
}))

const { themeClasses } = useTheme(props)
const { borderClasses } = useBorder(props, 'v-list-item')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="../../../../types/cypress" />

import { ref } from 'vue'
import { CenteredGrid } from '@/../cypress/templates'
import { VListItem } from '../..'

Expand All @@ -20,4 +21,21 @@ describe('VListItem', () => {
wrapper.get('.v-list-item-title').contains('foo')
wrapper.get('.v-list-item-subtitle').contains('bar')
})

// https://github.com/vuetifyjs/vuetify/issues/13893
it('should use active-color for active item', () => {
cy.mount({
setup () {
const model = ref<boolean>(false)
const onClick = () => model.value = !model.value

return () => (
<CenteredGrid width="200px">
<VListItem title="foo" subtitle="bar" active-color="success" active={model.value} onClick={onClick} />
<VListItem title="foo" subtitle="bar" active-color="success" active={!model.value} onClick={onClick} />
</CenteredGrid>
)
},
}).get('.v-list-item').eq(0).click().should('have.class', 'text-success')
})
})
19 changes: 12 additions & 7 deletions packages/vuetify/src/composables/variant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import { useColor } from '@/composables/color'

// Utilities
import { computed } from 'vue'
import { computed, unref } from 'vue'
import { propsFactory } from '@/util'

// Types
import type { PropType } from 'vue'
import type { MaybeRef } from '@/util'

export const allowedVariants = ['contained', 'outlined', 'plain', 'text', 'contained-text'] as const

Expand Down Expand Up @@ -38,15 +39,19 @@ export const makeVariantProps = propsFactory({
},
}, 'variant')

export function useVariant (props: VariantProps, name: string) {
export function useVariant (props: MaybeRef<VariantProps>, name: string) {
const variantClasses = computed(() => {
return `${name}--variant-${props.variant}`
const { variant } = unref(props)
return `${name}--variant-${variant}`
})

const { colorClasses, colorStyles } = useColor(computed(() => ({
text: props.textColor,
[props.variant === 'contained' ? 'background' : 'text']: props.color,
})))
const { colorClasses, colorStyles } = useColor(computed(() => {
const { textColor, variant, color } = unref(props)
return {
text: textColor,
[variant === 'contained' ? 'background' : 'text']: color,
}
}))

return { colorClasses, colorStyles, variantClasses }
}