Skip to content

Commit

Permalink
Fix table search in edge cases
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 432952643
  • Loading branch information
jameswex authored and LIT team committed Mar 7, 2022
1 parent 8993f9b commit 036283b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lit_nlp/client/elements/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,13 @@ export class DataTable extends ReactiveElement {
// clang-format on
}

private columnNameToId(name: string) {
return name.replace(/\s+/g, '');
}

renderColumnHeader(header: ColumnHeader) {
const title = header.name;
const headerId = this.columnNameToId(title);

const handleBackgroundClick = (e: Event) => {
this.resetView();
Expand Down Expand Up @@ -705,7 +710,8 @@ export class DataTable extends ReactiveElement {
// Focus cursor on newly-shown input box.
if (this.showColumnMenu) {
window.requestAnimationFrame(() => {
const inputElem = this.shadowRoot!.querySelector(`th#${title} .togglable-menu-holder input`) as HTMLElement;
const inputElem = this.shadowRoot!.querySelector(
`th#${headerId} .togglable-menu-holder input`) as HTMLElement;
inputElem.focus();
});
}
Expand Down Expand Up @@ -738,7 +744,7 @@ export class DataTable extends ReactiveElement {

// clang-format off
return html`
<th id=${title} @click=${handleBackgroundClick}>
<th id=${headerId} @click=${handleBackgroundClick}>
<div class=${headerClasses} title=${title}>
<div class="header-holder">
<div @click=${toggleSort}>${header.html!}</div>
Expand Down
1 change: 1 addition & 0 deletions lit_nlp/client/modules/multilabel_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class MultilabelModule extends LitModule {
<lit-data-table
.columnNames=${columnNames}
.data=${rows}
searchEnabled
></lit-data-table>
</div>`;
}
Expand Down

0 comments on commit 036283b

Please sign in to comment.