Skip to content

Commit

Permalink
fixed docs duplicate tree reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-zino committed Jul 23, 2023
1 parent fc64efd commit 9fa8dcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
42 changes: 17 additions & 25 deletions packages/skeleton/src/lib/components/TreeView/TreeView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
*/
export function expandAll(): void {
const detailsElements = [...tree.querySelectorAll('details.tree-item')] as HTMLDetailsElement[];
detailsElements.forEach((details) => {
if (!details.open) {
const summary: HTMLElement | null = details.querySelector('summary.tree-item-summary');
if (summary) summary.click();
detailsElements.forEach(details => {
if(!details.open) {
const summary : HTMLElement | null = details.querySelector('summary.tree-item-summary');
if(summary) summary.click();
}
});
}
Expand All @@ -66,10 +66,10 @@
*/
export function collapseAll() {
const detailsElements = [...tree.querySelectorAll('details.tree-item')] as HTMLDetailsElement[];
detailsElements.forEach((details) => {
if (details.open) {
const summary: HTMLElement | null = details.querySelector('summary.tree-item-summary');
if (summary) summary.click();
detailsElements.forEach(details => {
if(details.open) {
const summary : HTMLElement | null = details.querySelector('summary.tree-item-summary');
if(summary) summary.click();
}
});
}
Expand All @@ -79,10 +79,10 @@
*/
export function selectAll() {
const detailsElements = [...tree.querySelectorAll('details.tree-item')] as HTMLDetailsElement[];
detailsElements.forEach((details) => {
const input: HTMLInputElement | null = details.querySelector('input[type="checkbox"].tree-item-checkbox');
if (!input) return;
if (!input.checked) {
detailsElements.forEach(details => {
const input : HTMLInputElement | null = details.querySelector('input[type="checkbox"].tree-item-checkbox');
if(!input) return;
if(!input.checked) {
// needs delay
setTimeout(() => {
input.click();
Expand All @@ -96,10 +96,10 @@
*/
export function deselectAll() {
const detailsElements = [...tree.querySelectorAll('details.tree-item')] as HTMLDetailsElement[];
detailsElements.forEach((details) => {
const input: HTMLInputElement | null = details.querySelector('input[type="checkbox"].tree-item-checkbox');
if (!input) return;
if (input.checked) {
detailsElements.forEach(details => {
const input : HTMLInputElement | null = details.querySelector('input[type="checkbox"].tree-item-checkbox');
if(!input) return;
if(input.checked){
// needs delay
setTimeout(() => {
input.click();
Expand Down Expand Up @@ -130,14 +130,6 @@
let tree: HTMLDivElement;
</script>

<div
bind:this={tree}
class="tree {classesBase}"
data-testid="tree"
role="tree"
aria-multiselectable="true"
aria-label={labelledby}
aria-disabled={disabled}
>
<div bind:this={tree} class="tree {classesBase}" data-testid="tree" role="tree" aria-multiselectable="true" aria-label={labelledby} aria-disabled={disabled}>
<slot />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
let childrenMultiple: TreeViewItem[] = [];
let expandTree: TreeView;
let selectTree: TreeView;
let selectMultiple: string[] = [];
</script>
Expand Down Expand Up @@ -677,7 +678,7 @@ tree.collapseAll();
<p>Note: These functions are excecuted only in <code class="code">multiple</code> selection mode.</p>
<DocsPreview background="neutral" regionFooter="flex justify-center gap-4">
<svelte:fragment slot="preview">
<TreeView selection multiple bind:this={expandTree}>
<TreeView selection multiple bind:this={selectTree}>
<TreeViewItem bind:group={selectMultiple} name="s_medium" value="books">
<svelte:fragment slot="lead">
<i class="fa-solid fa-book-skull" />
Expand All @@ -699,8 +700,8 @@ tree.collapseAll();
</TreeView>
</svelte:fragment>
<svelte:fragment slot="footer">
<button class="btn variant-filled-primary" on:click={expandTree.selectAll}> Select all </button>
<button class="btn variant-filled-secondary" on:click={expandTree.deselectAll}> Deselect all </button>
<button class="btn variant-filled-primary" on:click={selectTree.selectAll}> Select all </button>
<button class="btn variant-filled-secondary" on:click={selectTree.deselectAll}> Deselect all </button>
</svelte:fragment>
<svelte:fragment slot="source">
<CodeBlock
Expand Down

0 comments on commit 9fa8dcf

Please sign in to comment.