Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unselect on click and Enter #116

Merged
merged 2 commits into from
Jul 6, 2024
Merged
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
40 changes: 38 additions & 2 deletions packages/components/src/tree-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// Distributed under the terms of the Modified BSD License.

import {
isTreeItemElement,
treeViewTemplate as template,
TreeView
TreeView,
type TreeItem
} from '@microsoft/fast-foundation';
import { treeViewStyles as styles } from './tree-view.styles.js';

Expand All @@ -14,7 +16,41 @@ import { treeViewStyles as styles } from './tree-view.styles.js';
* @public
* @tagname jp-tree-view
*/
class JupyterTreeView extends TreeView {}
class JupyterTreeView extends TreeView {
/**
* Handles click events bubbling up
*
* @internal
*/
public handleClick(e: Event): boolean | void {
if (e.defaultPrevented) {
// handled, do nothing
return;
}

if (!(e.target instanceof Element)) {
// not a tree item, ignore
return true;
}

let item = e.target as Element | null;
while (item && !isTreeItemElement(item)) {
item = item.parentElement;

// Escape if we get out of the tree view component
if (item === this) {
item = null;
}
}

if (item && !(item as TreeItem).disabled) {
// Force selection - it is not possible to unselect
(item as TreeItem).selected = true;
}

return;
}
}

/**
* A function that returns a {@link @microsoft/fast-foundation#TreeView} registration for configuring the component with a DesignSystem.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/tree-view/tree-view.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Template: StoryFn = (args): HTMLElement => {
<jp-tree-item>Nested item 3</jp-tree-item>
</jp-tree-item>
<jp-tree-item expanded>
Root item 2
Root <em style="padding: 0 0.2rem;">item</em> 2
<jp-tree-item>
Flowers
<jp-tree-item disabled>Daisy</jp-tree-item>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading