carbon-design-system / carbon-components-svelte

Svelte implementation of the Carbon Design System
https://svelte.carbondesignsystem.com
Apache License 2.0
2.71k stars 261 forks source link

feat(tree-view): add `showNode` accessor #1844

Closed metonym closed 1 year ago

metonym commented 1 year ago

Closes #1377

TreeView already exposes an expandNodes accessor.

treeview.expandNodes((node) => {
  return /^IBM/.test(node.text);
});

However, it's currently left to the user to "find" a specific node that they want to expand. The existing accessor also only applied to "expandable" nodes (i.e., nodes with children).

This PR addresses the use case of making an explicit node visible by adding a new accessor showNode. It accepts a node ID, and, if found, will expand, select, and focus the node.

treeview.showNode(nodeId);

Demo

https://github.com/carbon-design-system/carbon-components-svelte/assets/10718366/034e88ab-baed-4319-b1c8-ea1629244dd3