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

Add option to always show actions #2419

Merged
merged 1 commit into from
Dec 28, 2021
Merged
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
77 changes: 68 additions & 9 deletions src/components/ListItem/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@
</ActionButton>
</template>
</listItem>
<listItem
:title="'Title of the element'"
:bold="false"
:force-display-actions="true"
:details="'One hour ago'"
:counter-number="44"
counterType="highlighted">
<template #icon>
<avatar :size="44" user="janedoe" display-name="Jane Doe" />
</template>
<template #subtitle>
In this slot you can put both text and other components such as icons
</template>
<CounterBubble #counter>
7
</CounterBubble>
<template #actions>
<ActionButton>
Button one
</ActionButton>
<ActionButton>
Button two
</ActionButton>
<ActionButton>
Button three
</ActionButton>
</template>
</listItem>
<listItem
:title="'Title of the element'"
:bold="false">
Expand Down Expand Up @@ -129,7 +157,7 @@
{{ title }}
</span>
<span
v-if="hasDetails && !displayActions"
v-if="showDetails"
class="line-one__details">
{{ details }}
</span>
Expand All @@ -144,7 +172,7 @@
</span>

<!-- Counter -->
<span v-if="!displayActions" class="line-two__counter">
<span v-if="showCounter" class="line-two__counter">
<CounterBubble
v-if="counterNumber != 0"
:type="counterType">
Expand All @@ -156,7 +184,7 @@

<!-- Actions -->
<div
v-show="displayActions"
v-show="displayActionsOnHoverFocus && !forceDisplayActions"
class="list-item-content__actions"
@click.prevent.stop="">
<Actions
Expand All @@ -170,6 +198,21 @@
</Actions>
</div>
</div>
<!-- Actions -->
<div
v-show="forceDisplayActions"
class="list-item-content__actions"
@click.prevent.stop="">
<Actions
ref="actions"
menu-align="right"
:aria-label="actionsAriaLabel"
@update:open="handleActionsUpdateOpen">
<!-- @slot Provide the actions for the right side quick menu -->
<slot
name="actions" />
</Actions>
</div>
</div>

<!-- @slot Extra elements below the item -->
Expand Down Expand Up @@ -285,6 +328,14 @@ export default {
return ['highlighted', 'outlined', ''].indexOf(value) !== -1
},
},

/**
* To be used only when the elements in the actions menu are very important
*/
forceDisplayActions: {
type: Boolean,
default: false,
},
},

data() {
Expand All @@ -293,7 +344,7 @@ export default {
focused: false,
hasActions: false,
hasSubtitle: false,
displayActions: false,
displayActionsOnHoverFocus: false,
menuOpen: false,
}
},
Expand All @@ -320,14 +371,22 @@ export default {
}
},

showCounter() {
return !this.displayActionsOnHoverFocus || this.forceDisplayActions
},

showDetails() {
return this.hasDetails && (!this.displayActionsOnHoverFocus || this.forceDisplayActions)
},

},

watch: {

menuOpen(newValue) {
// A click outside both the menu and the root element hides the actions again
if (!newValue && !this.hovered) {
this.displayActions = false
this.displayActionsOnHoverFocus = false
}
},
},
Expand All @@ -354,13 +413,13 @@ export default {

showActions() {
if (this.hasActions) {
this.displayActions = true
this.displayActionsOnHoverFocus = true
}
this.hovered = false
},

hideActions() {
this.displayActions = false
this.displayActionsOnHoverFocus = false
},

/**
Expand All @@ -380,7 +439,7 @@ export default {
*/
handleMouseleave() {
if (!this.menuOpen) {
this.displayActions = false
this.displayActionsOnHoverFocus = false
}
this.hovered = false
},
Expand All @@ -396,7 +455,7 @@ export default {
this.$refs.actions.$refs.menuButton.focus()
this.focused = false
} else {
this.displayActions = false
this.displayActionsOnHoverFocus = false
this.$refs.actions.$refs.menuButton.blur()
}
},
Expand Down