Skip to content

Commit

Permalink
feat(VList): allow group activator to be activated without open children
Browse files Browse the repository at this point in the history
fixes #19441
  • Loading branch information
yuwu9145 committed May 10, 2024
1 parent a6340ac commit b49a70b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/vuetify/src/components/VList/VList.tsx
Expand Up @@ -88,6 +88,10 @@ export const makeVListProps = propsFactory({
disabled: Boolean,
expandIcon: String,
collapseIcon: String,
groupActivatorActivatable: {
type: Boolean,
default: false,
},
lines: {
type: [Boolean, String] as PropType<'one' | 'two' | 'three' | false>,
default: 'one',
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VList/VListGroup.tsx
Expand Up @@ -78,7 +78,7 @@ export const VListGroup = genericComponent<VListGroupSlots>()({
const toggleIcon = computed(() => isOpen.value ? props.collapseIcon : props.expandIcon)
const activatorDefaults = computed(() => ({
VListItem: {
active: isOpen.value,
// active: isOpen.value,
activeColor: props.activeColor,
baseColor: props.baseColor,
color: props.color,
Expand Down
9 changes: 0 additions & 9 deletions packages/vuetify/src/components/VList/VListItem.sass
Expand Up @@ -318,12 +318,3 @@

.v-list-group__items .v-list-item
padding-inline-start: calc(#{$base-padding} + var(--indent-padding)) !important

.v-list-group__header.v-list-item--active
&:not(:focus-visible)
.v-list-item__overlay
opacity: 0

&:hover
.v-list-item__overlay
opacity: calc(#{map.get(settings.$states, 'hover')} * var(--v-theme-overlay-multiplier))
14 changes: 10 additions & 4 deletions packages/vuetify/src/components/VList/VListItem.tsx
Expand Up @@ -28,7 +28,7 @@ import { Ripple } from '@/directives/ripple'

// Utilities
import { computed, watch } from 'vue'
import { deprecate, EventProp, genericComponent, propsFactory, useRender } from '@/util'
import { deprecate, EventProp, genericComponent, noop, propsFactory, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -173,12 +173,13 @@ export const VListItem = genericComponent<VListItemSlots>()({

function onClick (e: MouseEvent) {
emit('click', e)

}
function onSelect (e: MouseEvent) {
if (!isClickable.value) return

link.navigate?.(e)

if (isGroupActivator) return
if (!root.groupActivatorActivatable && isGroupActivator) return

if (root.activatable.value) {
activate(!isActivated.value, e)
Expand Down Expand Up @@ -241,7 +242,10 @@ export const VListItem = genericComponent<VListItemSlots>()({
]}
href={ link.href.value }
tabindex={ isClickable.value ? (list ? -2 : 0) : undefined }
onClick={ onClick }
onClick={[
onSelect,
root.groupActivatorActivatable ? () => noop : onClick,
]}
onKeydown={ isClickable.value && !isLink.value && onKeyDown }
v-ripple={ isClickable.value && props.ripple }
>
Expand All @@ -264,6 +268,7 @@ export const VListItem = genericComponent<VListItemSlots>()({
key="prepend-icon"
density={ props.density }
icon={ props.prependIcon }
onClick={ root.groupActivatorActivatable ? onClick : () => noop }
/>
)}
</>
Expand Down Expand Up @@ -318,6 +323,7 @@ export const VListItem = genericComponent<VListItemSlots>()({
key="append-icon"
density={ props.density }
icon={ props.appendIcon }
onClick={ root.groupActivatorActivatable ? onClick : () => noop }
/>
)}

Expand Down
4 changes: 4 additions & 0 deletions packages/vuetify/src/composables/nested/nested.ts
Expand Up @@ -45,6 +45,7 @@ export type OpenStrategyProp = 'single' | 'multiple' | 'list' | OpenStrategy

export interface NestedProps {
activatable: boolean
groupActivatorActivatable: boolean
selectable: boolean
activeStrategy: ActiveStrategyProp | undefined
selectStrategy: SelectStrategyProp | undefined
Expand All @@ -66,6 +67,7 @@ type NestedProvide = {
parents: Ref<Map<unknown, unknown>>
activatable: Ref<boolean>
selectable: Ref<boolean>
groupActivatorActivatable: Ref<boolean>
opened: Ref<Set<unknown>>
activated: Ref<Set<unknown>>
selected: Ref<Map<unknown, 'on' | 'off' | 'indeterminate'>>
Expand Down Expand Up @@ -93,6 +95,7 @@ export const emptyNested: NestedProvide = {
activate: () => null,
select: () => null,
activatable: ref(false),
groupActivatorActivatable: ref(false),
selectable: ref(false),
opened: ref(new Set()),
activated: ref(new Set()),
Expand Down Expand Up @@ -196,6 +199,7 @@ export const useNested = (props: NestedProps) => {
root: {
opened,
activatable: toRef(props, 'activatable'),
groupActivatorActivatable: toRef(props, 'groupActivatorActivatable'),
selectable: toRef(props, 'selectable'),
activated,
selected,
Expand Down

0 comments on commit b49a70b

Please sign in to comment.