Skip to content

Commit

Permalink
refactor(ActionList): use bool data hasEnabledChild
Browse files Browse the repository at this point in the history
Check if there is any child that is enabled.

This is somewhat simpler than storing an array of the disabled children
and comparing it's length to the length of the array of non-seperator children.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Apr 29, 2024
1 parent b64d837 commit 233d1ab
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/components/Menu/ActionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:force-menu="true"
:data-text-action-entry="actionEntry.key"
:data-text-action-active="activeKey"
:disabled="isDisabled"
:disabled="!isEnabled"
@update:open="onOpenChange">
<template #icon>
<component :is="icon" :key="iconKey" />
Expand Down Expand Up @@ -77,7 +77,7 @@ export default {
},
data: () => ({
visible: false,
disabledChildren: [],
hasEnabledChild: true,
}),
computed: {
currentChild() {
Expand Down Expand Up @@ -130,8 +130,8 @@ export default {
return this.actionEntry.label
},
isDisabled() {
return !this.forceEnabled && this.disabledChildren.length === this.children.filter((child) => !child.isSeparator).length
isEnabled() {
return this.forceEnabled || this.hasEnabledChild
},
},
mounted() {
Expand All @@ -158,13 +158,11 @@ export default {
this.$emit('trigged', entry)
},
checkStateOfChildren() {
this.disabledChildren = this.children.filter((child) => {
if (child.isSeparator) {
return false
}
const { disabled } = getActionState(child, this.$editor)
return disabled
})
this.hasEnabledChild = this.children.some(child => this.isChildEnabled(child))
},
isChildEnabled(child) {
return !child.isSeparator
&& !getActionState(child, this.$editor).disabled
},
},
}
Expand Down

0 comments on commit 233d1ab

Please sign in to comment.