Skip to content

Commit 296fd89

Browse files
authored
Merge pull request #1 from Amphiluke/keyboard-interactions
Keyboard interactions
2 parents db0632e + 46b774b commit 296fd89

File tree

14 files changed

+718
-688
lines changed

14 files changed

+718
-688
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ A mandatory attribute `name` is used by the `<cbx-tree>` component to construct
185185
<cbx-tree name="reading-list[]"></cbx-tree>
186186
```
187187

188+
### `nohover`
189+
190+
By default, items in the `<cbx-tree>` component grab focus and get highlighted when pointer hovers over them, similarly to options in the `<select>` element’s dropdown. A Boolean attribute `nohover` makes the `<cbx-tree>` component deactivate this behaviour, so that items only become selected when clicked or focused by keyboard navigation (similarly to options in a `<select>` with the `multiple` attribute specified).
191+
192+
```html
193+
<cbx-tree name="reading-list[]" nohover></cbx-tree>
194+
```
195+
188196
## Instance properties
189197

190198
The `CbxTree` interface also inherits properties from its parent, [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement).
@@ -212,6 +220,10 @@ console.log('Checked values:', readingList.formData.getAll('reading-list[]'));
212220

213221
Reflects the value of the element’s [`name` attribute](#name).
214222

223+
### `CbxTree.noHover`
224+
225+
Reflects the value of the element’s [`nohover` attribute](#nohover).
226+
215227
### `CbxTree.subtreeProvider`
216228

217229
The `subtreeProvider` property is used in cases where on-demand subtree loading is required. If your initial tree doesn’t contain data for some nested subtrees, you may define your custom function for subtree generation/fetching which will be called when the user expands the target item for the first time.
@@ -317,8 +329,8 @@ The `<cbx-tree>` element provides a few CSS custom properties (variables) that y
317329
| `--cbx-tree-toggle-closed-mask` | `<url>`¹ | Mask image for the toggle button in the collapsed state |
318330
| `--cbx-tree-toggle-open-mask` | `<url>` | Mask image for the toggle button in the expanded state |
319331
| `--cbx-tree-toggle-pending-mask` | `<url>` | Mask image for the toggle button in the pending state |
320-
| `--cbx-tree-label-hover-bg` | `<color>`² | Background color for the highlighted item’s label |
321-
| `--cbx-tree-label-hover-fg` | `<color>` | Text color for the highlighted item’s label |
332+
| `--cbx-tree-label-focus-bg` | `<color>`² | Background color for the highlighted item’s label |
333+
| `--cbx-tree-label-focus-fg` | `<color>` | Text color for the highlighted item’s label |
322334
| `--cbx-tree-nesting-indent` | `<length>`³ | Indentation size for nested subtrees |
323335

324336
¹ https://developer.mozilla.org/en-US/docs/Web/CSS/url_value \

dist/cbx-tree.d.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ export default class CbxTree extends HTMLElement {
1111
#private;
1212

1313
static get formAssociated(): true;
14+
static get observedAttributes(): string[];
1415
subtreeProvider: ((parentValue: string) => Promise<CbxRawTreeItem[]>) | null;
1516
get formData(): FormData;
1617
get form(): HTMLFormElement | null;
1718
get name(): string | null;
1819
set name(value: string);
1920
get disabled(): boolean;
2021
set disabled(value: boolean);
22+
get noHover(): boolean;
23+
set noHover(value: boolean);
2124
get type(): string;
2225

2326
constructor();
2427

28+
attributeChangedCallback(name: string): void;
2529
formDisabledCallback(disabled: boolean): void;
2630
formResetCallback(): void;
2731
formStateRestoreCallback(state: string, mode: string): void;

dist/cbx-tree.mjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/cbx-tree.mjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ cbx-tree[data-theme='custom'] {
8686
--cbx-tree-toggle-closed-mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" width="14" height="14"><path d="M3 7L11 7M7 3L7 11" stroke="black"/></svg>');
8787
--cbx-tree-toggle-open-mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 14" width="14" height="14"><path d="M3 7L11 7" stroke="black"/></svg>');
8888
--cbx-tree-nesting-indent: 1.3em;
89-
--cbx-tree-label-hover-bg: rgb(from SelectedItem r g b / 0.2);
90-
--cbx-tree-label-hover-fg: currentColor;
89+
--cbx-tree-label-focus-bg: rgb(from SelectedItem r g b / 0.2);
90+
--cbx-tree-label-focus-fg: currentColor;
9191

9292
&::part(item) {
9393
--line-color: rgb(from currentColor r g b / 0.3);

index-prod.html

Lines changed: 0 additions & 268 deletions
This file was deleted.

0 commit comments

Comments
 (0)