Skip to content

Commit

Permalink
fix(components): tree list item js error (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
owilliams320 authored Nov 6, 2023
1 parent d81f657 commit 2ee44df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libs/components/src/tree-list/tree-list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { customElement, property } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import styles from './tree-list-item.scss?inline';

import '../icon/icon';

declare global {
interface HTMLElementTagNameMap {
'cv-tree-list-item': CovalentTreeListItem;
Expand Down Expand Up @@ -82,4 +84,4 @@ export class CovalentTreeListItem extends LitElement {
}
}

export default CovalentTreeListItem;
export default CovalentTreeListItem;
8 changes: 4 additions & 4 deletions libs/components/src/tree-list/tree-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ document.addEventListener('select', (e: Event) => {
const handleSelect = (e: Event): void => {
// All cv-tree-list-item components.
const items: any[] = Array.from(
document.querySelectorAll('cv-tree-list-item')
document?.querySelectorAll('cv-tree-list-item')
);

// Currently selected item.
const target: HTMLElement = e.target as HTMLElement;
const current = target.shadowRoot!.querySelector('div.itemContent');
const current = target.shadowRoot?.querySelector('div.itemContent');

// Find previously selected element and remove the styling.
items.forEach((item) => {
item
.shadowRoot!.querySelector('div.itemContent')
.shadowRoot?.querySelector('div.itemContent')
?.classList.remove('selected');
});

// Add the selected styling to the currently selected item.
current!.classList.add('selected');
current?.classList.add('selected');
};

export default CovalentTreeList;

0 comments on commit 2ee44df

Please sign in to comment.