Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/syntax/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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.

Expand Down
158 changes: 150 additions & 8 deletions src/Elastic.Documentation.Site/Assets/markdown/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@
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-toggle,
.filterable-table-facets,
.filterable-table-clear {
display: none !important;
}

Expand All @@ -275,34 +277,122 @@
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;
}

/* The search box takes the row, with the Filters button beside it. */
.filterable-table-search-row {
display: flex;
gap: 0.5rem;
}

.filterable-table-search {
min-width: 16rem;
padding: 0.375rem 0.625rem;
flex: 1 1 auto;
min-width: 0;
padding: 0.5rem 0.75rem;
border: 1px solid var(--color-grey-30);
border-radius: 6px;
font-size: 0.875rem;
}

.filterable-table-facet {
/* 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;

/* 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;
}
}

.filterable-table-facet {
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);
}

/* The browser's own arrow sits against the right border. Draw one inset
from the edge instead, in the text color, and leave room for it. */
.filterable-table-facet select {
width: 100%;
min-width: 0;
appearance: none;
padding: 0.25rem 2rem 0.25rem 0.5rem;
padding: 0.375rem 2rem 0.375rem 0.5rem;
border: 1px solid var(--color-grey-30);
border-radius: 6px;
background-color: var(--color-white);
Expand All @@ -325,6 +415,21 @@
background-size: 0.375rem 0.375rem;
background-repeat: no-repeat;
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;
}

/* Forced-colors mode (Windows High Contrast) drops gradient backgrounds,
Expand All @@ -337,8 +442,45 @@
}

.filterable-table-status {
margin-inline-start: auto;
font-size: 0.8125rem;
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;
background: none;
font-size: 0.8125rem;
color: var(--color-blue-elastic);
cursor: pointer;

&:hover {
text-decoration: underline;
}

&[hidden] {
display: none;
}
}
}
Loading
Loading