Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit a481cdb

Browse files
committed
Hide search button when no rows are available
1 parent 8a90f6b commit a481cdb

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

__tests__/TableAddSearchRow.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ describe('TableAddSearchRow.vue', () => {
3737
expect(newRows[0]).toEqual("name");
3838
});
3939

40+
it('hides the button when the only row is the global search', () => {
41+
const component = mount(TableAddSearchRow, {
42+
propsData: {
43+
rows: {
44+
global: {
45+
key: "global",
46+
label: "global",
47+
value: null,
48+
},
49+
},
50+
51+
onAdd() { }
52+
}
53+
});
54+
55+
const dropdownButton = component.find("button[aria-haspopup='true']");
56+
expect(dropdownButton.exists()).toBeFalsy();
57+
});
4058

4159
it('hides the rows where a value is set', () => {
4260
const component = mount(TableAddSearchRow, {

js/Components/TableAddSearchRow.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default {
2121
},
2222
2323
computed: {
24+
hasRows() {
25+
return filter(this.rows, (row) => row.key !== "global").length > 0;
26+
},
27+
2428
rowsLeft() {
2529
return filter(this.rows, (row) => this.showRow(row)).length > 0;
2630
},

js/Tailwind2/TableAddSearchRow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<ButtonWithDropdown ref="dropdown" :disabled="!rowsLeft" class="w-auto">
2+
<ButtonWithDropdown ref="dropdown" v-if="hasRows" :disabled="!rowsLeft" class="w-auto">
33
<template #button>
44
<svg
55
xmlns="http://www.w3.org/2000/svg"

0 commit comments

Comments
 (0)