Skip to content
5 changes: 5 additions & 0 deletions .changeset/dry-canyons-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sit-onyx": minor
---

feat(OnyxDataGrid) implemented a column search inside the hideColumns feature.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ const features = computed(() => [withHideColumns.value]);
</script>

<template>
<OnyxDataGrid :columns :data :features />
<OnyxDataGrid :columns :data :features class="data-grid" />
</template>

<style lang="scss" scoped>
.data-grid {
padding-bottom: 4rem;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,49 @@ test("should hide and show columns", async ({ mount }) => {
});
});

test("should filter hidden columns via search", async ({ mount }) => {
const state = ref<(keyof Entry)[]>([]);
// ARRANGE
const component = await mount(
<TestCase onUpdate:state={(newState) => (state.value = newState)} allHidable />,
);
const revealButton = component.getByRole("button", { name: "Show hidden columns" });
const menuItem = component.getByRole("menuitem", { name: "Hide column" });
const openMoreActions = async (name: string) =>
component
.getByRole("columnheader", { name: `${name} Toggle column actions`, exact: true })
.getByLabel("Toggle column actions")
.click();

await openMoreActions("a");
await component.getByRole("menuitem", { name: "Hide column" }).click();
await openMoreActions("c");
await menuItem.click();

await revealButton.click();

const searchInput = component.getByRole("textbox", { name: "Filter the list items" });

await test.step("Filter the list", async () => {
await searchInput.fill("a");

await expect(component.getByRole("menuitem", { name: "a", exact: true })).toBeVisible();
await expect(component.getByRole("menuitem", { name: "c", exact: true })).toBeHidden();
await expect(component).toHaveScreenshot("data-grid-hide-columns-search-filtered.png");
});

await test.step("Clear search via clear button", async () => {
await component.getByRole("button", { name: "Clear" }).click();
await expect(searchInput).toHaveValue("");
await expect(component.getByRole("menuitem", { name: "c", exact: true })).toBeVisible();
});

await test.step("Search with no results", async () => {
await searchInput.fill("non-existent-column");
await expect(component.getByRole("menuitem")).toHaveCount(0);
});
});

test("last Column should not be hidable", async ({ mount }) => {
const state = ref<(keyof Entry)[]>([]);

Expand Down
Comment thread
ChristianBusshoff marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { iconCircleInformation, iconEyeDisabled, iconPlusSmall } from "@sit-onyx/icons";
import { computed, h, ref, toRef, type AriaAttributes, type Ref } from "vue";
import type { ComponentSlots } from "vue-component-type-helpers";
import { normalizedIncludes } from "../../../../utils/strings.js";
import OnyxIcon from "../../../OnyxIcon/OnyxIcon.vue";
import OnyxMiniSearch from "../../../OnyxMiniSearch/OnyxMiniSearch.vue";
import OnyxFlyoutMenu from "../../../OnyxNavBar/modules/OnyxFlyoutMenu/OnyxFlyoutMenu.vue";
import OnyxMenuItem from "../../../OnyxNavBar/modules/OnyxMenuItem/OnyxMenuItem.vue";
import OnyxSystemButton from "../../../OnyxSystemButton/OnyxSystemButton.vue";
Expand Down Expand Up @@ -32,6 +34,8 @@ export const useHideColumns = <TEntry extends DataGridEntry>(
columnConfig.value.filter((c) => hiddenColumnKeys.value.has(c.key)),
);

const searchTerm = ref("");

const flyoutMenu = () =>
h(
OnyxFlyoutMenu,
Expand All @@ -50,17 +54,30 @@ export const useHideColumns = <TEntry extends DataGridEntry>(
...trigger,
}),
options: () => {
return Array.from(hiddenColumns.value)
.sort((a, b) => Intl.Collator(i18n.locale.value).compare(a.label, b.label))
.map(({ key, label }) =>
h(
OnyxMenuItem,
{
onClick: () => hiddenColumnKeys.value.delete(key),
},
() => label,
return [
h(OnyxMiniSearch, {
label: i18n.t.value("select.searchInputLabel"),
modelValue: searchTerm.value,
"onUpdate:modelValue": (value: string) => (searchTerm.value = value),
onClear: () => (searchTerm.value = ""),
autofocus: true,
}),
Array.from(hiddenColumns.value)
.filter(({ label }) => {
if (!searchTerm.value) return true;
return normalizedIncludes(label, searchTerm.value);
})
.sort((a, b) => Intl.Collator(i18n.locale.value).compare(a.label, b.label))
.map(({ key, label }) =>
h(
OnyxMenuItem,
{
onClick: () => hiddenColumnKeys.value.delete(key),
},
() => label,
),
),
);
];
},
} satisfies ComponentSlots<typeof OnyxFlyoutMenu>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ defineExpose({
:class="['onyx-component', 'onyx-mini-search', densityClass]"
v-bind="rootAttrs"
:style="{ '--onyx-placeholder-character-count': placeholder.length }"
@click.stop
>
<input
ref="input"
Expand Down
Loading