Skip to content

Commit 4a95697

Browse files
authored
fix(VChipGroup): support center-active (#22050)
fixes #22046
1 parent e6c39bc commit 4a95697

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

packages/vuetify/src/components/VChip/VChip.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { VAvatar } from '@/components/VAvatar'
88
import { VChipGroupSymbol } from '@/components/VChipGroup/VChipGroup'
99
import { VDefaultsProvider } from '@/components/VDefaultsProvider'
1010
import { VIcon } from '@/components/VIcon'
11+
import { VSlideGroupSymbol } from '@/components/VSlideGroup/VSlideGroup'
1112

1213
// Composables
1314
import { makeBorderProps, useBorder } from '@/composables/border'
@@ -29,7 +30,7 @@ import { genOverlays, makeVariantProps, useVariant } from '@/composables/variant
2930
import vRipple from '@/directives/ripple'
3031

3132
// Utilities
32-
import { computed, toDisplayString, toRef } from 'vue'
33+
import { computed, toDisplayString, toRef, watch } from 'vue'
3334
import { EventProp, genericComponent, propsFactory } from '@/util'
3435

3536
// Types
@@ -133,7 +134,10 @@ export const VChip = genericComponent<VChipSlots>()({
133134
const { themeClasses } = provideTheme(props)
134135

135136
const isActive = useProxiedModel(props, 'modelValue')
137+
136138
const group = useGroupItem(props, VChipGroupSymbol, false)
139+
const slideGroup = useGroupItem(props, VSlideGroupSymbol, false)
140+
137141
const link = useLink(props, attrs)
138142
const isLink = toRef(() => props.link !== false && link.isLink.value)
139143
const isClickable = computed(() =>
@@ -154,6 +158,16 @@ export const VChip = genericComponent<VChipSlots>()({
154158
},
155159
}))
156160

161+
watch(isActive, val => {
162+
if (val) {
163+
group?.register()
164+
slideGroup?.register()
165+
} else {
166+
group?.unregister()
167+
slideGroup?.unregister()
168+
}
169+
})
170+
157171
const { colorClasses, colorStyles, variantClasses } = useVariant(() => {
158172
const showColor = !group || group.isSelected.value
159173
return ({

packages/vuetify/src/components/VTabs/__tests__/VTabs.spec.browser.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('VTabs', () => {
4444
</VTabs>
4545
))
4646

47+
await nextTick()
4748
expect(screen.getAllByCSS('.v-tab')[0]).toHaveClass('v-tab--selected')
4849

4950
model.value = 'bar'

packages/vuetify/src/composables/group.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface GroupItemProvide {
5555
value: Ref<unknown>
5656
disabled: Ref<boolean | undefined>
5757
group: GroupProvide
58+
register: () => void
59+
unregister: () => void
5860
}
5961

6062
export const makeGroupProps = propsFactory({
@@ -118,15 +120,16 @@ export function useGroupItem (
118120
const value = toRef(() => props.value)
119121
const disabled = computed(() => !!(group.disabled.value || props.disabled))
120122

121-
group.register({
122-
id,
123-
value,
124-
disabled,
125-
}, vm)
123+
function register () {
124+
group?.register({ id, value, disabled }, vm)
125+
}
126126

127-
onBeforeUnmount(() => {
128-
group.unregister(id)
129-
})
127+
function unregister () {
128+
group?.unregister(id)
129+
}
130+
131+
onMounted(() => register())
132+
onBeforeUnmount(() => unregister())
130133

131134
const isSelected = computed(() => {
132135
return group.isSelected(id)
@@ -155,6 +158,8 @@ export function useGroupItem (
155158
value,
156159
disabled,
157160
group,
161+
register,
162+
unregister,
158163
}
159164
}
160165

0 commit comments

Comments
 (0)