From 11c809471d6e27ce15ad41ac591074b5868cafaf Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:39:46 -0500 Subject: [PATCH 1/7] Lay out filterable table controls in three rows The search box, the dropdowns, and the count shared one wrapping row, so each new dropdown squeezed the search box and the rows wrapped unevenly. The controls now have three rows: the search box on its own, the dropdowns in an equal-width grid with their labels above them, and the count. A "Clear filters" button appears next to the count while anything is filtered, and a dropdown that's narrowing the table gets a highlighted border. Co-Authored-By: Claude Opus 5.5 --- .../Assets/markdown/table.css | 77 ++++++++++++++++--- .../web-components/FilterableTable.test.ts | 71 ++++++++++++++++- .../Assets/web-components/FilterableTable.ts | 57 ++++++++++++-- 3 files changed, 185 insertions(+), 20 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/markdown/table.css b/src/Elastic.Documentation.Site/Assets/markdown/table.css index a334f7b5bd..fe98e1c93e 100644 --- a/src/Elastic.Documentation.Site/Assets/markdown/table.css +++ b/src/Elastic.Documentation.Site/Assets/markdown/table.css @@ -256,7 +256,8 @@ that reads like the complete table. An unfiltered table prints with no controls at all, since there is nothing to disclose. */ .filterable-table-search, - .filterable-table-facet { + .filterable-table-facets, + .filterable-table-clear { display: none !important; } @@ -275,39 +276,95 @@ display: block; } + /* Three rows: the search box on its own, the dropdowns in a grid, then + the count and the "Clear filters" button. The search box and the + dropdowns never compete for the same row, so neither one squeezes or + wraps the other. */ .filterable-table-controls { display: flex; - flex-wrap: wrap; - align-items: center; + flex-direction: column; gap: 0.75rem; margin: 0.75rem 0; } .filterable-table-search { - min-width: 16rem; - padding: 0.375rem 0.625rem; + width: 100%; + padding: 0.5rem 0.75rem; border: 1px solid var(--color-grey-30); border-radius: 6px; font-size: 0.875rem; } + /* Equal columns that wrap as the page narrows, so the dropdowns line up + whatever their labels and values are. */ + .filterable-table-facets { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); + gap: 0.75rem; + + &:empty { + display: none; + } + } + .filterable-table-facet { - display: inline-flex; - align-items: center; - gap: 0.375rem; + display: flex; + flex-direction: column; + gap: 0.25rem; + min-width: 0; font-size: 0.875rem; } + .filterable-table-facet-label { + font-size: 0.8125rem; + font-weight: 600; + color: var(--color-ink-light); + } + .filterable-table-facet select { - padding: 0.25rem 0.5rem; + width: 100%; + min-width: 0; + padding: 0.375rem 0.5rem; border: 1px solid var(--color-grey-30); border-radius: 6px; + background-color: var(--color-white); font-size: 0.875rem; + text-overflow: ellipsis; + } + + /* A dropdown that's narrowing the table, so readers can see at a glance + which filters are on. */ + .filterable-table-facet[data-active] select { + border-color: var(--color-blue-elastic); + box-shadow: 0 0 0 1px var(--color-blue-elastic); + } + + .filterable-table-summary { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.75rem; } .filterable-table-status { - margin-inline-start: auto; font-size: 0.8125rem; color: var(--color-grey-100); } + + .filterable-table-clear { + padding: 0; + border: 0; + background: none; + font-size: 0.8125rem; + color: var(--color-blue-elastic); + cursor: pointer; + + &:hover { + text-decoration: underline; + } + + &[hidden] { + display: none; + } + } } diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts index 13b0f5e8d0..cffa4f8dcd 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts @@ -534,9 +534,9 @@ describe('filterable-table author-chosen dropdowns', () => { ` const facetLabels = () => - Array.from(document.querySelectorAll('.filterable-table-facet')).map( - (f) => f.textContent?.split(':')[0] - ) + Array.from( + document.querySelectorAll('.filterable-table-facet-label') + ).map((label) => label.textContent) it('offers a dropdown for every qualifying column by default', () => { document.body.innerHTML = SCORES_HTML('') @@ -636,3 +636,68 @@ describe('filterable-table author-chosen dropdowns', () => { expect(facetLabels()).toEqual(['Provider']) }) }) + +describe('filterable-table control layout', () => { + const clearButton = () => + document.querySelector('.filterable-table-clear')! + const search = () => + document.querySelector('.filterable-table-search')! + const select = () => + document.querySelector( + '.filterable-table-facet select' + )! + + it('puts search, dropdowns, and the count in separate rows', () => { + mount() + const rows = Array.from( + document.querySelector('.filterable-table-controls')!.children + ).map((el) => el.className) + expect(rows).toEqual([ + 'filterable-table-search', + 'filterable-table-facets', + 'filterable-table-summary', + ]) + expect( + document.querySelector('.filterable-table-facet-label')?.textContent + ).toBe('Support status') + }) + + it('shows Clear filters only while something is filtered', () => { + mount() + expect(clearButton().hidden).toBe(true) + + search().value = 'apache' + search().dispatchEvent(new Event('input')) + expect(clearButton().hidden).toBe(false) + + search().value = '' + search().dispatchEvent(new Event('input')) + expect(clearButton().hidden).toBe(true) + }) + + it('marks a dropdown that is narrowing the table', () => { + mount() + const facet = document.querySelector('.filterable-table-facet')! + expect(facet.hasAttribute('data-active')).toBe(false) + + select().value = 'Core' + select().dispatchEvent(new Event('change')) + expect(facet.hasAttribute('data-active')).toBe(true) + }) + + it('resets search and dropdowns from Clear filters', () => { + mount() + search().value = 'host' + search().dispatchEvent(new Event('input')) + select().value = 'Core' + select().dispatchEvent(new Event('change')) + expect(visibleRows()).toHaveLength(1) + + clearButton().click() + expect(search().value).toBe('') + expect(select().value).toBe('') + expect(visibleRows()).toHaveLength(4) + expect(clearButton().hidden).toBe(true) + expect(document.activeElement).toBe(search()) + }) +}) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts index 97d20882ce..c6d6f8554d 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts @@ -35,6 +35,8 @@ class FilterableTableElement extends HTMLElement { private facets: Facet[] = [] private status: HTMLElement | null = null private controls: HTMLElement | null = null + private facetList: HTMLElement | null = null + private clearButton: HTMLButtonElement | null = null private facetSignature = '' private observer: MutationObserver | null = null private settleTimer = 0 @@ -204,6 +206,11 @@ class FilterableTableElement extends HTMLElement { return specs } + /** + * Lays the controls out in three rows: the search box on its own, the + * dropdowns in a grid with their labels above them, and the count with a + * "Clear filters" button that shows only while something is filtered. + */ private buildControls(): void { const controls = document.createElement('div') controls.className = 'filterable-table-controls' @@ -217,27 +224,52 @@ class FilterableTableElement extends HTMLElement { controls.appendChild(search) this.searchInput = search + const facetList = document.createElement('div') + facetList.className = 'filterable-table-facets' + controls.appendChild(facetList) + this.facetList = facetList + + const summary = document.createElement('div') + summary.className = 'filterable-table-summary' + const status = document.createElement('span') status.className = 'filterable-table-status' status.setAttribute('role', 'status') status.setAttribute('aria-live', 'polite') - controls.appendChild(status) + summary.appendChild(status) this.status = status + const clear = document.createElement('button') + clear.type = 'button' + clear.className = 'filterable-table-clear' + clear.textContent = 'Clear filters' + clear.hidden = true + clear.addEventListener('click', () => this.clearFilters()) + summary.appendChild(clear) + this.clearButton = clear + + controls.appendChild(summary) this.controls = controls this.insertBefore(controls, this.firstChild) this.renderFacets() } + /** Empties the search box, sets every dropdown back to All, and returns focus to search. */ + private clearFilters(): void { + if (this.searchInput) this.searchInput.value = '' + for (const facet of this.facets) facet.select.value = '' + this.applyFilters() + this.searchInput?.focus() + } + /** * Builds the dropdowns, or rebuilds them when late-rendering content has * changed what the columns contain. A no-op when nothing changed, so * incidental DOM churn costs nothing. */ private renderFacets(): void { - const controls = this.controls - const status = this.status - if (!controls || !status) return + const facetList = this.facetList + if (!facetList) return const specs = this.facetSpecs() const signature = JSON.stringify(specs) @@ -254,7 +286,10 @@ class FilterableTableElement extends HTMLElement { for (const spec of specs) { const wrapper = document.createElement('label') wrapper.className = 'filterable-table-facet' - wrapper.append(`${spec.label}: `) + const name = document.createElement('span') + name.className = 'filterable-table-facet-label' + name.textContent = spec.label + wrapper.appendChild(name) const select = document.createElement('select') select.setAttribute('aria-label', `Filter by ${spec.label}`) @@ -268,8 +303,7 @@ class FilterableTableElement extends HTMLElement { select.addEventListener('change', () => this.applyFilters()) wrapper.appendChild(select) - // Keep the count last in the control row. - controls.insertBefore(wrapper, status) + facetList.appendChild(wrapper) this.facets.push({ colIndex: spec.colIndex, select }) } } @@ -341,6 +375,15 @@ class FilterableTableElement extends HTMLElement { // count, so it can't be mistaken for the complete table. this.dataset.filtered = String(visible < this.rows.length) + // Mark the dropdowns that narrow the table, and offer a way to undo + // everything only while something is set. + for (const facet of this.facets) + facet.select + .closest('label') + ?.toggleAttribute('data-active', facet.select.value !== '') + if (this.clearButton) + this.clearButton.hidden = query === '' && activeFacets.length === 0 + const text = `Showing ${visible} of ${this.rows.length}` // Only touch the live region when the count really changed, so typing // doesn't queue one announcement per keystroke. From a8ccfedf103472f28efe3fd0922ee1df355fffeb Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:41:25 -0500 Subject: [PATCH 2/7] Mention Clear filters in the filterable table docs Co-Authored-By: Claude Opus 5.5 --- docs/syntax/tables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax/tables.md b/docs/syntax/tables.md index 11bda53bbd..0f9b144549 100644 --- a/docs/syntax/tables.md +++ b/docs/syntax/tables.md @@ -149,7 +149,7 @@ The `{table}` directive's `:matrix:` option highlights the whole row *and* colum ## Filterable table -The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. +The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. While a search or filter is set, a **Clear filters** button next to the count resets them all. The table is rendered server-side and stays fully usable without JavaScript, because the controls are added only as a progressive enhancement. The filter inputs don't print. A filter stays applied when you print, so a printed filtered table keeps its "Showing N of M" count to show that rows are missing. From a5448eac2ea334e5a2fc54b7b714d494ec614844 Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:46:22 -0500 Subject: [PATCH 3/7] Say so when a filterable table has no matching rows A search or filter that matched nothing left only the header row, which looked like a broken table. A message now appears under the header row, naming what's narrowing the table: the search, the filters, or both. It isn't a live region, because the count already announces "Showing 0 of N". The reset button is now labeled "Clear", which also fits search-only tables. Co-Authored-By: Claude Opus 5.5 --- docs/syntax/tables.md | 2 +- .../Assets/markdown/table.css | 21 ++++ .../web-components/FilterableTable.test.ts | 109 ++++++++++++++++++ .../Assets/web-components/FilterableTable.ts | 32 ++++- 4 files changed, 161 insertions(+), 3 deletions(-) diff --git a/docs/syntax/tables.md b/docs/syntax/tables.md index 0f9b144549..5b2b821648 100644 --- a/docs/syntax/tables.md +++ b/docs/syntax/tables.md @@ -149,7 +149,7 @@ The `{table}` directive's `:matrix:` option highlights the whole row *and* colum ## Filterable table -The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. While a search or filter is set, a **Clear filters** button next to the count resets them all. +The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. While a search or filter is set, a **Clear** button next to the count resets them all. When nothing matches, a message under the header row says so. The table is rendered server-side and stays fully usable without JavaScript, because the controls are added only as a progressive enhancement. The filter inputs don't print. A filter stays applied when you print, so a printed filtered table keeps its "Showing N of M" count to show that rows are missing. diff --git a/src/Elastic.Documentation.Site/Assets/markdown/table.css b/src/Elastic.Documentation.Site/Assets/markdown/table.css index fe98e1c93e..5135998541 100644 --- a/src/Elastic.Documentation.Site/Assets/markdown/table.css +++ b/src/Elastic.Documentation.Site/Assets/markdown/table.css @@ -351,6 +351,27 @@ color: var(--color-grey-100); } + /* When nothing matches, the message sits under the header row like an + empty table body: the table's bottom margin goes, and the message + carries on its side and bottom borders. */ + filterable-table[data-empty] .table-wrapper { + margin-bottom: 0; + } + + .filterable-table-empty { + margin: 0 0 1rem; + padding: 1.5rem 1rem; + border: 1px solid var(--color-grey-20); + border-top: 0; + text-align: center; + font-size: 0.875rem; + color: var(--color-ink-light); + + &[hidden] { + display: none; + } + } + .filterable-table-clear { padding: 0; border: 0; diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts index cffa4f8dcd..41206fe27b 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts @@ -701,3 +701,112 @@ describe('filterable-table control layout', () => { expect(document.activeElement).toBe(search()) }) }) + +describe('filterable-table empty results', () => { + const message = () => + document.querySelector('.filterable-table-empty')! + const search = (value: string) => { + const input = document.querySelector( + '.filterable-table-search' + )! + input.value = value + input.dispatchEvent(new Event('input')) + } + const choose = (value: string) => { + const select = document.querySelector( + '.filterable-table-facet select' + )! + select.value = value + select.dispatchEvent(new Event('change')) + } + + it('labels the reset button Clear', () => { + mount() + expect( + document.querySelector('.filterable-table-clear')?.textContent + ).toBe('Clear') + }) + + it('hides the message while rows match', () => { + mount() + expect(message().hidden).toBe(true) + search('apache') + expect(message().hidden).toBe(true) + }) + + it('explains an empty table after a search', () => { + mount() + search('nothing-matches') + expect(message().hidden).toBe(false) + expect(message().textContent).toBe('No rows match your search.') + }) + + it('explains an empty table after filters', () => { + // Each value matches some rows, but no row is both an Exporter and + // Extended, so only the two filters together empty the table. + document.body.innerHTML = ` + + + + + + + + +
NameTypeStatus
aReceiverCore
bReceiverExtended
cExporterCore
+
` + customElements.upgrade(document.body) + const [type, status] = Array.from( + document.querySelectorAll( + '.filterable-table-facet select' + ) + ) + type.value = 'Exporter' + type.dispatchEvent(new Event('change')) + status.value = 'Extended' + status.dispatchEvent(new Event('change')) + expect(message().hidden).toBe(false) + expect(message().textContent).toBe('No rows match your filters.') + }) + + it('names both search and filters when both are set', () => { + mount() + choose('Extended') + search('filelog') + expect(message().hidden).toBe(false) + expect(message().textContent).toBe( + 'No rows match your search and filters.' + ) + expect( + document + .querySelector('filterable-table')! + .hasAttribute('data-empty') + ).toBe(true) + }) + + it('hides the message again after Clear', () => { + mount() + search('nothing-matches') + document + .querySelector('.filterable-table-clear')! + .click() + expect(message().hidden).toBe(true) + expect( + document + .querySelector('filterable-table')! + .hasAttribute('data-empty') + ).toBe(false) + }) + + it('keeps one message when an enhanced host is cloned', () => { + mount() + const host = document.querySelector('filterable-table')! + const clone = host.cloneNode(true) as HTMLElement + clone.querySelector('.filterable-table-controls')?.remove() + delete clone.dataset.enhanced + document.body.appendChild(clone) + expect(clone.querySelectorAll('.filterable-table-empty')).toHaveLength( + 1 + ) + }) +}) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts index c6d6f8554d..6e96baaa0f 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts @@ -37,6 +37,7 @@ class FilterableTableElement extends HTMLElement { private controls: HTMLElement | null = null private facetList: HTMLElement | null = null private clearButton: HTMLButtonElement | null = null + private emptyMessage: HTMLElement | null = null private facetSignature = '' private observer: MutationObserver | null = null private settleTimer = 0 @@ -209,7 +210,8 @@ class FilterableTableElement extends HTMLElement { /** * Lays the controls out in three rows: the search box on its own, the * dropdowns in a grid with their labels above them, and the count with a - * "Clear filters" button that shows only while something is filtered. + * "Clear" button that shows only while something is filtered. A message + * below the table says so when nothing matches. */ private buildControls(): void { const controls = document.createElement('div') @@ -242,7 +244,7 @@ class FilterableTableElement extends HTMLElement { const clear = document.createElement('button') clear.type = 'button' clear.className = 'filterable-table-clear' - clear.textContent = 'Clear filters' + clear.textContent = 'Clear' clear.hidden = true clear.addEventListener('click', () => this.clearFilters()) summary.appendChild(clear) @@ -251,6 +253,18 @@ class FilterableTableElement extends HTMLElement { controls.appendChild(summary) this.controls = controls this.insertBefore(controls, this.firstChild) + + // Shown under the header row when nothing matches, so an empty table + // doesn't look broken. It isn't a live region: the count above it + // already announces "Showing 0 of N". A fullscreen copy is cloned + // from an enhanced host, so drop any message the clone carried over. + this.querySelector(':scope > .filterable-table-empty')?.remove() + const empty = document.createElement('p') + empty.className = 'filterable-table-empty' + empty.hidden = true + this.appendChild(empty) + this.emptyMessage = empty + this.renderFacets() } @@ -384,6 +398,20 @@ class FilterableTableElement extends HTMLElement { if (this.clearButton) this.clearButton.hidden = query === '' && activeFacets.length === 0 + // Say why the table is empty, naming what's narrowing it. + const none = visible === 0 + this.toggleAttribute('data-empty', none) + if (this.emptyMessage) { + this.emptyMessage.hidden = !none + if (none) + this.emptyMessage.textContent = + query !== '' && activeFacets.length > 0 + ? 'No rows match your search and filters.' + : query !== '' + ? 'No rows match your search.' + : 'No rows match your filters.' + } + const text = `Showing ${visible} of ${this.rows.length}` // Only touch the live region when the count really changed, so typing // doesn't queue one announcement per keystroke. From 37ebbbcc62819e03e98ae5206c19152c0e59155a Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:47:20 -0500 Subject: [PATCH 4/7] Render the no-results message as a div so paragraph margins don't apply Co-Authored-By: Claude Opus 5.5 --- .../Assets/web-components/FilterableTable.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts index 6e96baaa0f..a463c83a76 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts @@ -259,7 +259,8 @@ class FilterableTableElement extends HTMLElement { // already announces "Showing 0 of N". A fullscreen copy is cloned // from an enhanced host, so drop any message the clone carried over. this.querySelector(':scope > .filterable-table-empty')?.remove() - const empty = document.createElement('p') + // A div, not a p: the page's paragraph styles would add a top margin. + const empty = document.createElement('div') empty.className = 'filterable-table-empty' empty.hidden = true this.appendChild(empty) From 15bd82f42e6613acc43a8836cc8815f3964865cf Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:57:41 -0500 Subject: [PATCH 5/7] Collapse filterable table dropdowns behind a Filters button Five dropdowns take several rows above a table before any data shows. The dropdowns now start collapsed behind a "Filters" button beside the search box. The button shows how many filters are on, visibly and in its accessible name, so readers can tell the table is narrowed with the panel shut. It's a disclosure button with aria-expanded and aria-controls, and it's hidden when the table has no dropdowns. Co-Authored-By: Claude Opus 5.5 --- .../Assets/markdown/table.css | 67 +++++++++++++++++- .../web-components/FilterableTable.test.ts | 66 ++++++++++++++++- .../Assets/web-components/FilterableTable.ts | 70 +++++++++++++++++-- 3 files changed, 195 insertions(+), 8 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/markdown/table.css b/src/Elastic.Documentation.Site/Assets/markdown/table.css index 5135998541..9d10904411 100644 --- a/src/Elastic.Documentation.Site/Assets/markdown/table.css +++ b/src/Elastic.Documentation.Site/Assets/markdown/table.css @@ -256,6 +256,7 @@ that reads like the complete table. An unfiltered table prints with no controls at all, since there is nothing to disclose. */ .filterable-table-search, + .filterable-table-toggle, .filterable-table-facets, .filterable-table-clear { display: none !important; @@ -287,8 +288,15 @@ margin: 0.75rem 0; } + /* The search box takes the row, with the Filters button beside it. */ + .filterable-table-search-row { + display: flex; + gap: 0.5rem; + } + .filterable-table-search { - width: 100%; + flex: 1 1 auto; + min-width: 0; padding: 0.5rem 0.75rem; border: 1px solid var(--color-grey-30); border-radius: 6px; @@ -302,6 +310,63 @@ grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.75rem; + /* display:grid would otherwise override the hidden attribute. */ + &:empty, + &[hidden] { + display: none; + } + } + + .filterable-table-toggle { + display: inline-flex; + flex: none; + align-items: center; + gap: 0.375rem; + padding: 0.375rem 0.75rem; + border: 1px solid var(--color-grey-30); + border-radius: 6px; + background: var(--color-white); + font-size: 0.875rem; + color: var(--color-ink-dark); + white-space: nowrap; + cursor: pointer; + + &:hover, + &[aria-expanded='true'] { + background: var(--color-grey-10); + } + + &[hidden] { + display: none; + } + } + + .filterable-table-toggle-icon, + .filterable-table-toggle-chevron { + width: 1rem; + height: 1rem; + } + + .filterable-table-toggle-chevron { + transition: transform 0.15s ease; + + [aria-expanded='true'] > & { + transform: rotate(180deg); + } + } + + /* How many filters are on, so the count stays visible with the panel shut. */ + .filterable-table-toggle-count { + min-width: 1.25rem; + padding: 0 0.375rem; + border-radius: 999px; + background: var(--color-blue-elastic); + font-size: 0.75rem; + font-weight: 600; + line-height: 1.25rem; + text-align: center; + color: var(--color-white); + &:empty { display: none; } diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts index 41206fe27b..6ed0aa1754 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.test.ts @@ -653,7 +653,7 @@ describe('filterable-table control layout', () => { document.querySelector('.filterable-table-controls')!.children ).map((el) => el.className) expect(rows).toEqual([ - 'filterable-table-search', + 'filterable-table-search-row', 'filterable-table-facets', 'filterable-table-summary', ]) @@ -810,3 +810,67 @@ describe('filterable-table empty results', () => { ) }) }) + +describe('filterable-table collapsible filters', () => { + const toggle = () => + document.querySelector('.filterable-table-toggle')! + const panel = () => + document.querySelector('.filterable-table-facets')! + const count = () => + document.querySelector('.filterable-table-toggle-count')!.textContent + + it('starts with the dropdowns collapsed behind a Filters button', () => { + mount() + expect(toggle().hidden).toBe(false) + expect(toggle().textContent).toContain('Filters') + expect(toggle().getAttribute('aria-expanded')).toBe('false') + expect(toggle().getAttribute('aria-controls')).toBe(panel().id) + expect(panel().hidden).toBe(true) + }) + + it('opens and closes the dropdowns from the button', () => { + mount() + toggle().click() + expect(panel().hidden).toBe(false) + expect(toggle().getAttribute('aria-expanded')).toBe('true') + toggle().click() + expect(panel().hidden).toBe(true) + expect(toggle().getAttribute('aria-expanded')).toBe('false') + }) + + it('counts the filters that are on, with the panel open or shut', () => { + mount() + expect(count()).toBe('') + expect(toggle().getAttribute('aria-label')).toBe('Filters') + + toggle().click() + const select = document.querySelector( + '.filterable-table-facet select' + )! + select.value = 'Core' + select.dispatchEvent(new Event('change')) + toggle().click() + + expect(panel().hidden).toBe(true) + expect(count()).toBe('1') + expect(toggle().getAttribute('aria-label')).toBe('Filters, 1 on') + }) + + it('gives each table its own panel id', () => { + document.body.innerHTML = TABLE_HTML + TABLE_HTML + customElements.upgrade(document.body) + const ids = Array.from( + document.querySelectorAll('.filterable-table-facets') + ).map((el) => el.id) + expect(new Set(ids).size).toBe(2) + }) + + it('hides the button when there are no dropdowns', () => { + document.body.innerHTML = TABLE_HTML.replace( + '', + '' + ) + customElements.upgrade(document.body) + expect(toggle().hidden).toBe(true) + }) +}) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts index a463c83a76..152e41d6e3 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts @@ -23,6 +23,14 @@ const SETTLE_MS = 150 // htmx swaps) can never trigger a rebuild while someone is using the filters. const WATCH_CEILING_MS = 5000 +// Gives each dropdown panel a unique id for its button's aria-controls. +let facetListIds = 0 + +// The Filters button: a funnel icon, the label, a count of the filters that +// are on (empty when none), and a chevron that flips when the panel opens. +// Static markup, with no reader or author text in it. +const TOGGLE_CONTENT = `Filters` + type Facet = { colIndex: number; select: HTMLSelectElement } type FacetSpec = { colIndex: number; label: string; values: string[] } @@ -38,6 +46,7 @@ class FilterableTableElement extends HTMLElement { private facetList: HTMLElement | null = null private clearButton: HTMLButtonElement | null = null private emptyMessage: HTMLElement | null = null + private toggleButton: HTMLButtonElement | null = null private facetSignature = '' private observer: MutationObserver | null = null private settleTimer = 0 @@ -208,10 +217,11 @@ class FilterableTableElement extends HTMLElement { } /** - * Lays the controls out in three rows: the search box on its own, the - * dropdowns in a grid with their labels above them, and the count with a - * "Clear" button that shows only while something is filtered. A message - * below the table says so when nothing matches. + * Lays the controls out in rows: the search box with a "Filters" button, + * the dropdowns in a grid with their labels above them (collapsed until + * the button opens them), and the count with a "Clear" button that shows + * only while something is filtered. A message below the table says so + * when nothing matches. */ private buildControls(): void { const controls = document.createElement('div') @@ -223,14 +233,33 @@ class FilterableTableElement extends HTMLElement { search.className = 'filterable-table-search' search.setAttribute('aria-label', 'Filter table') search.addEventListener('input', () => this.applyFilters()) - controls.appendChild(search) this.searchInput = search + // The dropdowns start collapsed behind a "Filters" button beside the + // search box. The button carries a count of the filters that are on, + // so readers can tell the table is narrowed even with the panel shut. const facetList = document.createElement('div') facetList.className = 'filterable-table-facets' - controls.appendChild(facetList) + facetList.id = `filterable-table-facets-${++facetListIds}` + facetList.hidden = true this.facetList = facetList + const toggle = document.createElement('button') + toggle.type = 'button' + toggle.className = 'filterable-table-toggle' + toggle.setAttribute('aria-expanded', 'false') + toggle.setAttribute('aria-controls', facetList.id) + toggle.innerHTML = TOGGLE_CONTENT + toggle.addEventListener('click', () => + this.showFilters(facetList.hidden) + ) + this.toggleButton = toggle + + const searchRow = document.createElement('div') + searchRow.className = 'filterable-table-search-row' + searchRow.append(search, toggle) + controls.append(searchRow, facetList) + const summary = document.createElement('div') summary.className = 'filterable-table-summary' @@ -269,6 +298,13 @@ class FilterableTableElement extends HTMLElement { this.renderFacets() } + /** Opens or closes the dropdown panel. */ + private showFilters(open: boolean): void { + if (!this.facetList || !this.toggleButton) return + this.facetList.hidden = !open + this.toggleButton.setAttribute('aria-expanded', String(open)) + } + /** Empties the search box, sets every dropdown back to All, and returns focus to search. */ private clearFilters(): void { if (this.searchInput) this.searchInput.value = '' @@ -321,6 +357,11 @@ class FilterableTableElement extends HTMLElement { facetList.appendChild(wrapper) this.facets.push({ colIndex: spec.colIndex, select }) } + + // No dropdowns, no button: a search-only table shows just the search box. + if (this.toggleButton) + this.toggleButton.hidden = this.facets.length === 0 + if (this.facets.length === 0) this.showFilters(false) } private watchLateContent(tbody: HTMLTableSectionElement): void { @@ -399,6 +440,23 @@ class FilterableTableElement extends HTMLElement { if (this.clearButton) this.clearButton.hidden = query === '' && activeFacets.length === 0 + // Count the filters that are on in the Filters button, visibly and in + // its accessible name. + if (this.toggleButton) { + const count = this.toggleButton.querySelector( + '.filterable-table-toggle-count' + ) + if (count) + count.textContent = + activeFacets.length > 0 ? String(activeFacets.length) : '' + this.toggleButton.setAttribute( + 'aria-label', + activeFacets.length > 0 + ? `Filters, ${activeFacets.length} on` + : 'Filters' + ) + } + // Say why the table is empty, naming what's narrowing it. const none = visible === 0 this.toggleAttribute('data-empty', none) From 48081a796cb6d980bd77dbf2ac4da74bae3c9ad5 Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 19:58:45 -0500 Subject: [PATCH 6/7] Mention the Filters button in the filterable table docs Co-Authored-By: Claude Opus 5.5 --- docs/syntax/tables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax/tables.md b/docs/syntax/tables.md index 5b2b821648..ae0aa069ef 100644 --- a/docs/syntax/tables.md +++ b/docs/syntax/tables.md @@ -149,7 +149,7 @@ The `{table}` directive's `:matrix:` option highlights the whole row *and* colum ## Filterable table -The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. While a search or filter is set, a **Clear** button next to the count resets them all. When nothing matches, a message under the header row says so. +The `{table}` directive's `:filterable:` option adds a search box above the table, plus a dropdown filter for each column that has a small number of repeated values — for example a type or status column. The dropdowns start collapsed behind a **Filters** button next to the search box, which shows how many filters are on. Search matches text in every column. Search and filters combine — each one you set narrows the results further. A live "Showing N of M" count is announced to assistive technologies. While a search or filter is set, a **Clear** button next to the count resets them all. When nothing matches, a message under the header row says so. The table is rendered server-side and stays fully usable without JavaScript, because the controls are added only as a progressive enhancement. The filter inputs don't print. A filter stays applied when you print, so a printed filtered table keeps its "Showing N of M" count to show that rows are missing. From 7c86e6ec42ffaf4cd2a617da8cac556e7659a463 Mon Sep 17 00:00:00 2001 From: Nastasha Solomon Date: Tue, 17 Nov 2026 20:27:32 -0500 Subject: [PATCH 7/7] Port the filter controls to the design-system table stylesheet With NAVIGATION_PREVIEW on, pages load ds.css instead of styles.css, and ds.css takes its table styles from Components/Markdown/Table/table.css. That file still styled the old one-row controls, so the new search row, the Filters button, the dropdown grid, Clear, and the no-results message were unstyled there, and the print rules didn't hide the new buttons. The design-system stylesheet now carries the same controls, written with its tokens so they follow its light and dark themes. The Filters button's icons also get width and height attributes, because the design-system reset makes SVGs block-level with no size of their own. Co-Authored-By: Claude Opus 5.5 --- .../Assets/web-components/FilterableTable.ts | 2 +- .../Components/Markdown/Table/table.css | 157 ++++++++++++++++-- 2 files changed, 148 insertions(+), 11 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts index 152e41d6e3..457950ffe2 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts +++ b/src/Elastic.Documentation.Site/Assets/web-components/FilterableTable.ts @@ -29,7 +29,7 @@ let facetListIds = 0 // The Filters button: a funnel icon, the label, a count of the filters that // are on (empty when none), and a chevron that flips when the panel opens. // Static markup, with no reader or author text in it. -const TOGGLE_CONTENT = `Filters` +const TOGGLE_CONTENT = `Filters` type Facet = { colIndex: number; select: HTMLSelectElement } type FacetSpec = { colIndex: number; label: string; values: string[] } diff --git a/src/Elastic.Documentation.Site/Components/Markdown/Table/table.css b/src/Elastic.Documentation.Site/Components/Markdown/Table/table.css index f12c7a5351..4d18075fce 100644 --- a/src/Elastic.Documentation.Site/Components/Markdown/Table/table.css +++ b/src/Elastic.Documentation.Site/Components/Markdown/Table/table.css @@ -229,15 +229,14 @@ dialog.table-modal thead th { background: var(--color-surface-sunken); } -/* The filter controls come from the filterable-table element. */ +/* The filter controls come from the filterable-table element: the search box with a Filters button, the dropdowns (collapsed until the button opens them), then the count and a Clear button. */ filterable-table { display: block; } .filterable-table-controls { display: flex; - flex-wrap: wrap; - align-items: center; + flex-direction: column; gap: var(--space-3); margin: var(--space-3) 0; } @@ -252,12 +251,106 @@ filterable-table { font-size: var(--text-sm); } +/* The search box takes the row, with the Filters button beside it. */ +.filterable-table-search-row { + display: flex; + gap: var(--space-2); +} + .filterable-table-search { - min-width: 16rem; + flex: 1 1 auto; + min-width: 0; + padding: var(--space-2) var(--space-3); +} + +.filterable-table-toggle { + display: inline-flex; + flex: none; + align-items: center; + gap: var(--space-2); + padding: var(--space-1) var(--space-3); + border: var(--border-width) solid var(--color-border-control); + border-radius: var(--radius-md); + background: var(--color-surface); + color: var(--color-text); + font-size: var(--text-sm); + white-space: nowrap; + cursor: pointer; +} + +.filterable-table-toggle:hover, +.filterable-table-toggle[aria-expanded='true'] { + background: var(--color-surface-sunken); +} + +.filterable-table-toggle[hidden] { + display: none; +} + +/* The design-system reset makes SVGs block-level with no size, so size the icons here. */ +.filterable-table-toggle-icon, +.filterable-table-toggle-chevron { + width: 1rem; + height: 1rem; +} + +.filterable-table-toggle-chevron { + transition: transform 0.15s ease; +} + +.filterable-table-toggle[aria-expanded='true'] + .filterable-table-toggle-chevron { + transform: rotate(180deg); +} + +/* How many filters are on, so the count stays visible with the panel shut. */ +.filterable-table-toggle-count { + min-width: 1.25rem; + padding: 0 var(--space-1); + border-radius: var(--radius-pill); + background: var(--color-accent); + color: var(--color-on-accent); + font-size: var(--text-xs); + font-weight: var(--weight-semibold); + line-height: 1.25rem; + text-align: center; +} + +.filterable-table-toggle-count:empty { + display: none; +} + +/* Equal columns that wrap as the page narrows, so the dropdowns line up whatever their labels and values are. */ +.filterable-table-facets { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); + gap: var(--space-3); +} + +/* display:grid would otherwise override the hidden attribute. */ +.filterable-table-facets:empty, +.filterable-table-facets[hidden] { + display: none; +} + +.filterable-table-facet { + display: flex; + flex-direction: column; + gap: var(--space-1); + min-width: 0; + font-size: var(--text-sm); +} + +.filterable-table-facet-label { + color: var(--color-text-muted); + font-size: var(--text-xs); + font-weight: var(--weight-semibold); } /* The browser's own arrow sits against the right border. Draw one inset from the edge instead, in the text colour, and leave room for it. */ .filterable-table-facet select { + width: 100%; + min-width: 0; appearance: none; padding-inline-end: calc(var(--space-2) + 1.25rem); background-image: @@ -278,25 +371,69 @@ filterable-table { calc(100% - 0.625rem) 50%; background-size: 0.375rem 0.375rem; background-repeat: no-repeat; + text-overflow: ellipsis; } -.filterable-table-facet { - display: inline-flex; +/* A dropdown that's narrowing the table, so readers can see at a glance which filters are on. */ +.filterable-table-facet[data-active] select { + border-color: var(--color-accent); + box-shadow: 0 0 0 var(--border-width) var(--color-accent); +} + +.filterable-table-summary { + display: flex; + flex-wrap: wrap; align-items: center; - gap: var(--space-2); - font-size: var(--text-sm); + gap: var(--space-3); } .filterable-table-status { - margin-inline-start: auto; color: var(--color-text-muted); font-size: var(--text-sm); } +.filterable-table-clear { + padding: 0; + border: 0; + background: none; + color: var(--color-accent); + font-size: var(--text-sm); + cursor: pointer; +} + +.filterable-table-clear:hover { + text-decoration: underline; +} + +.filterable-table-clear[hidden] { + display: none; +} + +/* When nothing matches, the message sits under the header row like an empty table body: the table's bottom margin goes, and the message carries on its side and bottom borders. */ +filterable-table[data-empty] .table-wrapper { + margin-bottom: 0; +} + +.filterable-table-empty { + margin: 0 0 var(--space-4); + padding: var(--space-5) var(--space-4); + border: var(--border-width) solid var(--color-border); + border-top: 0; + color: var(--color-text-muted); + font-size: var(--text-sm); + text-align: center; +} + +.filterable-table-empty[hidden] { + display: none; +} + @media print { .table-expand-btn, .filterable-table-search, - .filterable-table-facet { + .filterable-table-toggle, + .filterable-table-facets, + .filterable-table-clear { display: none; }