From ef108c92d20c1599ee676e7535958fbca9939626 Mon Sep 17 00:00:00 2001 From: portikM Date: Thu, 12 Sep 2024 21:56:14 -0400 Subject: [PATCH] fix(ktable): disable column visibility dropdown [KHCP-13248] --- src/components/KTable/ColumnVisibilityMenu.vue | 6 ++++++ src/components/KTable/KTable.vue | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/KTable/ColumnVisibilityMenu.vue b/src/components/KTable/ColumnVisibilityMenu.vue index 66e5c25b16..080c7da6e5 100644 --- a/src/components/KTable/ColumnVisibilityMenu.vue +++ b/src/components/KTable/ColumnVisibilityMenu.vue @@ -2,6 +2,7 @@
@@ -14,6 +15,7 @@ aria-label="Show/Hide Columns" class="menu-button" data-testid="column-visibility-menu-button" + :disabled="disabled" icon size="large" > @@ -91,6 +93,10 @@ const props = defineProps({ type: Object as PropType>, default: () => ({}), }, + disabled: { + type: Boolean, + default: false, + }, }) const isDropdownOpen = ref(false) diff --git a/src/components/KTable/KTable.vue b/src/components/KTable/KTable.vue index 784efab7d6..cfda443567 100644 --- a/src/components/KTable/KTable.vue +++ b/src/components/KTable/KTable.vue @@ -9,9 +9,10 @@ name="toolbar" :state="stateData" /> + tableHeaders.value.filter((header: TableHeader) => header.hidable).length > 0) const hasColumnVisibilityMenu = computed((): boolean => { - // has hidable columns, no error/loading/empty state - return !!(hasHidableColumns.value && - !props.error && !isTableLoading.value && !props.loading && (data.value && data.value.length)) + if (!hasHidableColumns.value || props.error) { + return false + } + + if (slots.toolbar) { + // when toolbar slot is present, we want to disable column visibility menu rather than hide it in certain states + return true + } + + return !isTableLoading.value && !props.loading && data.value && !!data.value.length }) +const columnVisibilityDisabled = computed((): boolean => isTableLoading.value || props.loading || !(data.value && data.value.length)) // columns whose visibility can be toggled const visibilityColumns = computed((): TableHeader[] => tableHeaders.value.filter((header: TableHeader) => header.hidable)) // visibility preferences from the host app (initialized by app)