@cscfi/csc-ui 4.0.0-alpha.3 → 4.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csc-ui.js +14328 -8058
- package/dist/custom-elements.json +8952 -4605
- package/dist/docs/c-alert/usage.md +24 -0
- package/dist/docs/c-autocomplete/usage.md +152 -0
- package/dist/docs/c-breadcrumb/usage.md +104 -0
- package/dist/docs/c-breadcrumb-item/usage.md +1 -0
- package/dist/docs/c-button-group/usage.md +14 -1
- package/dist/docs/c-checkbox/usage.md +53 -0
- package/dist/docs/c-date-picker/usage.md +224 -0
- package/dist/docs/c-main/usage.md +21 -1
- package/dist/docs/c-menu/usage.md +15 -0
- package/dist/docs/c-menu-item/usage.md +6 -0
- package/dist/docs/c-number-field/usage.md +112 -0
- package/dist/docs/c-option-value/usage.md +1 -0
- package/dist/docs/c-popover/usage.md +33 -0
- package/dist/docs/c-progress-bar/usage.md +23 -0
- package/dist/docs/c-progress-circle/usage.md +25 -0
- package/dist/docs/c-radio/usage.md +45 -0
- package/dist/docs/c-radio-group/usage.md +67 -0
- package/dist/docs/c-select/usage.md +127 -0
- package/dist/docs/c-side-navigation/usage.md +21 -0
- package/dist/docs/c-spinner/usage.md +21 -0
- package/dist/docs/c-switch/usage.md +36 -0
- package/dist/docs/c-tab-buttons/usage.md +7 -0
- package/dist/docs/c-table/usage.md +14 -0
- package/dist/docs/c-text-field/usage.md +106 -0
- package/dist/docs/c-time-picker/usage.md +170 -0
- package/dist/docs/c-toolbar/usage.md +17 -0
- package/dist/docs/c-tooltip/usage.md +30 -0
- package/dist/docs/c-tree-select/usage.md +156 -0
- package/dist/floating-ui.dom-DvzxEaDJ.js +1292 -0
- package/dist/styles/css/tailwind-theme.css +33 -0
- package/dist/styles/css/tokens.css +719 -197
- package/dist/vscode.css-custom-data.json +474 -20
- package/dist/vscode.html-custom-data.json +659 -57
- package/dist/web-types.json +2813 -697
- package/dist-types/components/c-alert/CAlert.vue.d.ts +18 -4
- package/dist-types/components/c-autocomplete/CAutocomplete.vue.d.ts +118 -21
- package/dist-types/components/c-breadcrumb/CBreadcrumb.vue.d.ts +35 -0
- package/dist-types/components/c-breadcrumb/fit.d.ts +29 -0
- package/dist-types/components/c-breadcrumb-item/CBreadcrumbItem.vue.d.ts +31 -0
- package/dist-types/components/c-button/CButton.vue.d.ts +4 -4
- package/dist-types/components/c-button-group/CButtonGroup.vue.d.ts +1 -1
- package/dist-types/components/c-checkbox/CCheckbox.vue.d.ts +3 -3
- package/dist-types/components/c-data-table/CDataTable.vue.d.ts +6 -2
- package/dist-types/components/c-date-picker/CDatePicker.vue.d.ts +282 -0
- package/dist-types/components/c-date-picker/dates.d.ts +119 -0
- package/dist-types/components/c-dropdown/CDropdown.vue.d.ts +50 -7
- package/dist-types/components/c-icon-button/CIconButton.vue.d.ts +1 -1
- package/dist-types/components/c-input/CInput.vue.d.ts +6 -6
- package/dist-types/components/c-list-item/CListItem.vue.d.ts +1 -1
- package/dist-types/components/c-main/CMain.vue.d.ts +10 -2
- package/dist-types/components/c-menu/CMenu.vue.d.ts +13 -3
- package/dist-types/components/c-menu-item/CMenuItem.vue.d.ts +30 -3
- package/dist-types/components/c-number-field/CNumberField.vue.d.ts +174 -0
- package/dist-types/components/c-number-field/numbers.d.ts +58 -0
- package/dist-types/components/c-otp-input/COtpInput.vue.d.ts +1 -1
- package/dist-types/components/c-pagination/CPagination.vue.d.ts +1 -1
- package/dist-types/components/c-popover/CPopover.vue.d.ts +43 -0
- package/dist-types/components/c-progress-circle/CProgressCircle.vue.d.ts +32 -0
- package/dist-types/components/c-radio/CRadio.vue.d.ts +7 -11
- package/dist-types/components/c-radio-group/CRadioGroup.vue.d.ts +10 -48
- package/dist-types/components/c-select/CSelect.vue.d.ts +115 -27
- package/dist-types/components/c-side-navigation/CSideNavigation.vue.d.ts +1 -1
- package/dist-types/components/c-side-navigation-item/CSideNavigationItem.vue.d.ts +1 -1
- package/dist-types/components/c-slider/CSlider.vue.d.ts +3 -3
- package/dist-types/components/c-sub-navigation-item/CSubNavigationItem.vue.d.ts +1 -1
- package/dist-types/components/c-tab-buttons/CTabButtons.vue.d.ts +1 -1
- package/dist-types/components/c-table/CTable.vue.d.ts +11 -1
- package/dist-types/components/c-table/injectTableStyles.d.ts +1 -0
- package/dist-types/components/c-tag/CTag.vue.d.ts +7 -0
- package/dist-types/components/c-tags/CTags.vue.d.ts +1 -1
- package/dist-types/components/c-text-field/CTextField.vue.d.ts +27 -10
- package/dist-types/components/c-time-picker/CTimePicker.vue.d.ts +210 -0
- package/dist-types/components/c-time-picker/times.d.ts +82 -0
- package/dist-types/components/c-toasts/CToasts.vue.d.ts +1 -1
- package/dist-types/components/c-toolbar/CToolbar.vue.d.ts +10 -1
- package/dist-types/components/c-tooltip/CTooltip.vue.d.ts +49 -0
- package/dist-types/components/c-tree-select/CTreeSelect.vue.d.ts +261 -0
- package/dist-types/index.d.ts +19 -2
- package/dist-types/shared/FieldMessage.vue.d.ts +21 -0
- package/dist-types/shared/PanelHeadingRow.vue.d.ts +13 -0
- package/dist-types/shared/SelectionIndicator.vue.d.ts +21 -0
- package/dist-types/shared/TypedField.vue.d.ts +46 -0
- package/dist-types/shared/appDefaults.d.ts +75 -0
- package/dist-types/shared/defineElement.d.ts +1 -0
- package/dist-types/shared/inputMask.d.ts +106 -0
- package/dist-types/shared/lightDismiss.d.ts +35 -0
- package/dist-types/shared/modalStack.d.ts +4 -3
- package/dist-types/shared/optionLabel.d.ts +18 -0
- package/dist-types/shared/pageLock.d.ts +26 -0
- package/dist-types/shared/peekCap.d.ts +35 -0
- package/dist-types/shared/popoverChain.d.ts +65 -0
- package/dist-types/shared/positionArea.d.ts +13 -0
- package/dist-types/shared/reducedMotion.d.ts +10 -0
- package/dist-types/shared/selectAll.d.ts +29 -0
- package/dist-types/shared/splitMatches.d.ts +18 -0
- package/dist-types/shared/useAnchoredPanel.d.ts +102 -0
- package/dist-types/shared/useDesignatedTrigger.d.ts +41 -0
- package/dist-types/shared/useFallbackPosition.d.ts +63 -0
- package/dist-types/shared/useHostStates.d.ts +25 -0
- package/dist-types/shared/useNarrowViewport.d.ts +19 -0
- package/dist-types/shared/useScrollStrip.d.ts +39 -0
- package/dist-types/shared/useStatusAnnouncer.d.ts +33 -0
- package/dist-types/shared/useTypedField.d.ts +103 -0
- package/dist-types/shared/visualViewport.d.ts +51 -0
- package/dist-types/tag-name-map.d.ts +769 -54
- package/dist-types/theme/chart-data.d.ts +51 -0
- package/dist-types/theme/ramp.d.ts +38 -0
- package/dist-types/theme/themeMode.d.ts +51 -0
- package/dist-types/types.d.ts +7 -0
- package/package.json +21 -9
- package/dist/css-anchor-positioning-fn-RTxo68pt.js +0 -6447
- package/dist-types/shared/anchorPolyfill.d.ts +0 -24
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
A time field that takes a typed time, or opens hour and minute columns for picking one, or a start and end time under `range`.
|
|
2
|
+
|
|
3
|
+
## Value
|
|
4
|
+
|
|
5
|
+
The value is a time of day as an ISO `HH:mm` string on a 24-hour clock —
|
|
6
|
+
`'14:05'` — or `null` when the field is empty. It carries no seconds, no date
|
|
7
|
+
and no timezone, and whatever the displayed `format` it keeps this one shape:
|
|
8
|
+
a field showing `14.05` or `2:05 PM` holds `'14:05'`. Bind it with `v-model`,
|
|
9
|
+
or listen for `change`:
|
|
10
|
+
|
|
11
|
+
```vue
|
|
12
|
+
<c-time-picker v-model="time" label="Start time" />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Under `range` the value becomes `{ start, end }`. Either end may be `null`
|
|
16
|
+
while only one is set — `{ start: '09:00', end: null }` — and a range with
|
|
17
|
+
neither end is `null`.
|
|
18
|
+
|
|
19
|
+
## Typing
|
|
20
|
+
|
|
21
|
+
The field is typeable first: clicking into it or focusing it never opens the
|
|
22
|
+
columns. Text is read when the user presses Enter or leaves the input, never
|
|
23
|
+
per keystroke. The `format` prop sets how times are shown and read — a pattern
|
|
24
|
+
of the tokens `H` or `HH` (a 24-hour hour), `h` or `hh` (a 12-hour hour, which
|
|
25
|
+
needs the period `a`) and `mm`, with any separators. The default is `HH.mm`;
|
|
26
|
+
`HH:mm` and `h:mm a` are common alternatives. The format is an app default, so
|
|
27
|
+
an app can set it once with `applyDefaults({ 'c-time-picker': { format: 'HH:mm' } })`.
|
|
28
|
+
|
|
29
|
+
Typing follows the format as it goes: the separator appears on its own (`930`
|
|
30
|
+
shows `9.30`), an hour closes early when its first digit can start no
|
|
31
|
+
two-digit hour, any of `.`, `:` or a space typed in place of the separator
|
|
32
|
+
shows as the format's own, and in a 12-hour format a typed `a` or `p` fills in
|
|
33
|
+
the whole AM or PM text. Reading is lenient:
|
|
34
|
+
|
|
35
|
+
| Typed | Reads as |
|
|
36
|
+
| ------- | -------------------------------------------- |
|
|
37
|
+
| `9` | `09:00` — a bare hour is on the hour |
|
|
38
|
+
| `930` | `09:30` — three or four digits split |
|
|
39
|
+
| `9.3` | `09:03` — one minute digit is that minute |
|
|
40
|
+
| `2 pm` | `14:00` — a period makes the hour 12-hour |
|
|
41
|
+
| `14.00` | `14:00`, also in a 12-hour field (`2:00 PM`) |
|
|
42
|
+
|
|
43
|
+
In a 12-hour field an hour typed without a period reads as AM.
|
|
44
|
+
|
|
45
|
+
Text that names no time that can be picked — `25.00`, a time outside `min`
|
|
46
|
+
and `max` — is **bad input**: the text stays as the user typed it, the value
|
|
47
|
+
becomes `null`, and the host exposes the `bad-input` custom state and a
|
|
48
|
+
read-only `badInput` property. The component never shows an error of its own;
|
|
49
|
+
deciding whether bad input is an error, and saying so, is the consumer's
|
|
50
|
+
validation:
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<c-time-picker
|
|
54
|
+
v-model="time"
|
|
55
|
+
:error-message="error"
|
|
56
|
+
:valid="!error"
|
|
57
|
+
label="Start time"
|
|
58
|
+
@change:text="error = $event.target.badInput ? 'Enter a time as hh.mm' : ''"
|
|
59
|
+
/>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every commit of typed text fires `change:text` with the text as typed
|
|
63
|
+
(`{ start, end }` under `range`), whether or not it changed the value.
|
|
64
|
+
|
|
65
|
+
## The columns
|
|
66
|
+
|
|
67
|
+
The clock button at the field's trailing edge, or Alt+ArrowDown in the input,
|
|
68
|
+
opens the columns: hours and minutes side by side, and an AM/PM column in a
|
|
69
|
+
12-hour format. The panel is a dialog: focus moves onto the hour column —
|
|
70
|
+
the value's hour, or the current hour when the field is empty — and Tab
|
|
71
|
+
cycles through the columns and the Now button (`show-now`) until the panel
|
|
72
|
+
closes.
|
|
73
|
+
|
|
74
|
+
Every pick commits at once and the panel stays open, so the hour can be fixed
|
|
75
|
+
after the minutes are picked (on a narrow viewport picks wait for a Done
|
|
76
|
+
button instead; see [Narrow viewports](#narrow-viewports)). The selected row rests at the top of its column:
|
|
77
|
+
it opens there and returns there after each pick, and so does a minute a pick
|
|
78
|
+
fills in. Scrolling a column only looks; it never picks. Picking into an empty field fills in the rest:
|
|
79
|
+
minute `00`, and the hour the hour column rests on. Moving in a column is
|
|
80
|
+
picking — each arrow key press commits, so a `change` handler doing network
|
|
81
|
+
work should debounce.
|
|
82
|
+
|
|
83
|
+
| Key | In a column |
|
|
84
|
+
| ------------------- | ------------------------------------------ |
|
|
85
|
+
| ArrowUp / ArrowDown | Previous / next row |
|
|
86
|
+
| Home / End | First / last row |
|
|
87
|
+
| PageUp / PageDown | Five rows up / down |
|
|
88
|
+
| Space | Pick the focused row |
|
|
89
|
+
| Enter | Pick the focused row and close |
|
|
90
|
+
| Escape | Close; what was picked stays |
|
|
91
|
+
| Tab | Next column (the end switch under `range`) |
|
|
92
|
+
|
|
93
|
+
Focus returns to the input when the panel closes.
|
|
94
|
+
|
|
95
|
+
## Minute step
|
|
96
|
+
|
|
97
|
+
`minute-step` spaces the minute column's rows: `15` lists `00`, `15`, `30`
|
|
98
|
+
and `45`. It only shapes the column — a typed `14.07` commits as `14:07` and
|
|
99
|
+
shows as an extra row between `00` and `15`. Require a step with your own
|
|
100
|
+
validation if it matters.
|
|
101
|
+
|
|
102
|
+
## Min and max
|
|
103
|
+
|
|
104
|
+
`min` and `max` are ISO `HH:mm` times. Rows outside them are disabled — an
|
|
105
|
+
hour only when none of its minutes fit — and a typed time outside them is bad
|
|
106
|
+
input. A pick never leaves them: picking hour 9 at `10:15` with `min="09:30"`
|
|
107
|
+
commits `09:30`. A `min` later than `max` is not a range across midnight; it
|
|
108
|
+
is ignored with a console warning.
|
|
109
|
+
|
|
110
|
+
## Ranges
|
|
111
|
+
|
|
112
|
+
With `range` the field holds two inputs, the start and the end, in one field
|
|
113
|
+
box, and the panel shows a Start | End switch above the columns. It opens on
|
|
114
|
+
the end last typed in; each end commits on its own as it is picked.
|
|
115
|
+
|
|
116
|
+
An end earlier than the start is an **overnight range** — `22:00` to `06:00`
|
|
117
|
+
spans midnight — and is kept as it is, never swapped or flagged. Where a range
|
|
118
|
+
must stay within one day, check it in your validation; ISO times compare
|
|
119
|
+
correctly as strings:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const sameDay =
|
|
123
|
+
!value || !value.start || !value.end || value.start <= value.end;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Now
|
|
127
|
+
|
|
128
|
+
`show-now` adds a Now button under the columns. Pressing it commits the
|
|
129
|
+
current time and closes the panel, unlike a pick in the columns, which leaves
|
|
130
|
+
it open. The time is the exact minute whatever `minute-step`: at 14:07 with a
|
|
131
|
+
step of 15 it commits `14:07`. Under `range` it sets the end the Start | End
|
|
132
|
+
switch shows.
|
|
133
|
+
|
|
134
|
+
```vue
|
|
135
|
+
<c-time-picker v-model="arrival" label="Arrival" show-now />
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The button is disabled, never hidden, while the current time is outside
|
|
139
|
+
`min` and `max`. Turn it on app-wide with
|
|
140
|
+
`applyDefaults({ 'c-time-picker': { showNow: true } })`.
|
|
141
|
+
|
|
142
|
+
## Texts
|
|
143
|
+
|
|
144
|
+
The AM and PM texts come from `texts` when given, then from the browser's
|
|
145
|
+
`Intl` data for the page's `lang`, then from the English built-ins — so a page
|
|
146
|
+
with `<html lang="fi">` shows `ap.` and `ip.` without any configuration. The
|
|
147
|
+
button, column and range labels are English unless `texts` replaces them. Set
|
|
148
|
+
them app-wide with `applyDefaults({ 'c-time-picker': { texts } })`.
|
|
149
|
+
|
|
150
|
+
## Narrow viewports
|
|
151
|
+
|
|
152
|
+
On a viewport narrower than 760px the columns open as a **fullscreen panel**:
|
|
153
|
+
a heading row with the field's `label` and a close button above the columns.
|
|
154
|
+
There the selected row rests in the middle of its column instead of the top,
|
|
155
|
+
in every column, so the selections line up even when a column fits.
|
|
156
|
+
|
|
157
|
+
The fullscreen panel ends in a Done button, and there picks wait in the
|
|
158
|
+
panel instead of committing: nothing is emitted until Done commits the time
|
|
159
|
+
— under `range` both ends at once — and closes the panel. The close button
|
|
160
|
+
and Escape close the panel without a change, discarding what was picked, and
|
|
161
|
+
so does the window growing past 760px while it is open. The Now button moves
|
|
162
|
+
the columns to the current time the same way, and Enter picks the focused
|
|
163
|
+
row and presses Done at once. Pressing Done before picking anything closes
|
|
164
|
+
the panel and changes nothing. The field stays typeable at every width.
|
|
165
|
+
|
|
166
|
+
## Related
|
|
167
|
+
|
|
168
|
+
`c-date-picker` is the same field for calendar dates. `c-text-field
|
|
169
|
+
type="time"` remains the browser's own time input — no columns, the browser's
|
|
170
|
+
format, and no ranges.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
The app-wide bar at the top of the dashboard layout: the logo, the service name and global actions such as the user menu or log out. It is pinned to the top of the viewport by default and stays there while the page scrolls; `static` keeps it in the page flow so it scrolls away with the content.
|
|
2
|
+
|
|
3
|
+
## Pinned or static
|
|
4
|
+
|
|
5
|
+
Pinned is the default: the bar sticks to the top edge of its scroll container — the document in the dashboard layout — as soon as the page scrolls past it. Set `static` to leave the bar in flow instead; it then scrolls away with the page and returns when the user scrolls back to the top. The 3.x `class="relative"` switch is gone; `static` replaces it.
|
|
6
|
+
|
|
7
|
+
## Inside c-main
|
|
8
|
+
|
|
9
|
+
In `c-main`'s dashboard layout the toolbar spans both columns above the side navigation and the page, below an optional banner. `c-main` follows the toolbar's mode: the desktop side navigation is pinned beneath a pinned toolbar, or to the top edge once a static toolbar has scrolled away. No extra markup is needed.
|
|
10
|
+
|
|
11
|
+
## Content
|
|
12
|
+
|
|
13
|
+
The bar is a horizontal flex row with a small gap. Push trailing actions to the right with `margin-inline-start: auto` on the first of them.
|
|
14
|
+
|
|
15
|
+
## Customization
|
|
16
|
+
|
|
17
|
+
Structural styling via `::part(root)`. The height is the library's layout value shared with `c-main`, so changing it on the part does not move the pinned side navigation.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
A non-interactive text hint shown when its trigger is hovered or keyboard-focused, floating in the top layer on the inverted surface tier.
|
|
2
|
+
|
|
3
|
+
Put the element the tooltip describes in the `trigger` slot and the hint in the `text` prop. For formatted content, use the `content` slot instead — it overrides the prop but must stay non-interactive: a tooltip is never focusable and can hold no links or buttons. If the content needs to be clicked, use `c-popover`.
|
|
4
|
+
|
|
5
|
+
The tooltip shows after a short hover delay (configurable via the `delay` prop) and immediately on keyboard focus. The trigger must be focusable for keyboard and screen-reader users to reach the hint — a `c-icon-button` or `c-button` qualifies; a bare `<span>` does not.
|
|
6
|
+
|
|
7
|
+
When the described element cannot be slotted, point the `trigger` prop at it instead — its document ID, or the element itself via property binding. The tooltip then wires hover/focus onto that element, mirrors the `aria-description` there, and anchors the bubble to it. Supplying both routes is a misuse: the prop wins, the slotted element gets no wiring, and a console warning flags it.
|
|
8
|
+
|
|
9
|
+
## When to use
|
|
10
|
+
|
|
11
|
+
- To name an icon-only control or clarify a truncated label.
|
|
12
|
+
- Never for content the user must interact with, or for information that is available nowhere else on the page for touch users — tooltips are unreliable on touch devices.
|
|
13
|
+
|
|
14
|
+
## Dismissal
|
|
15
|
+
|
|
16
|
+
The tooltip hides when the pointer leaves the trigger and panel, when focus leaves the trigger, and on Escape (without moving focus). The pointer can travel from the trigger onto the tooltip without it vanishing.
|
|
17
|
+
|
|
18
|
+
## Accessibility
|
|
19
|
+
|
|
20
|
+
The tooltip implements the WCAG 1.4.13 (Content on Hover or Focus) contract: dismissable, hoverable, persistent.
|
|
21
|
+
|
|
22
|
+
The tooltip content is mirrored onto the trigger (slotted or designated) as `aria-description`, so screen readers announce it with the trigger even while the bubble is closed. `aria-describedby` is not used because ARIA ID references cannot cross the shadow boundary between the light-DOM trigger and the shadow-DOM panel (ADR-0033).
|
|
23
|
+
|
|
24
|
+
## Layering
|
|
25
|
+
|
|
26
|
+
The panel is a native popover in the top layer: it is never clipped by ancestor overflow and paints above modals — correct for a tooltip triggered from inside one.
|
|
27
|
+
|
|
28
|
+
## Customization
|
|
29
|
+
|
|
30
|
+
Structural styling via `::part(trigger)` and `::part(panel)`. Colours come from the inverted-surface semantic tokens (`--c-surface-inverted`, `--c-on-surface-inverted`); override the tokens to re-theme.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
A hierarchical value-selection component: a readonly value field that opens a panel for browsing a tree one level at a time, or searching it as a whole, to commit one item.
|
|
2
|
+
|
|
3
|
+
## Items
|
|
4
|
+
|
|
5
|
+
The tree is the `items` property: an array of `{ value, name }` entries where
|
|
6
|
+
an entry with a non-empty `children` array is a branch and any other entry is
|
|
7
|
+
a leaf. Values must be unique across the whole tree. An optional `code` — a
|
|
8
|
+
classification number, say — is shown before the name in a muted column and
|
|
9
|
+
is matched by the search. Arrays have no attribute form, so bind `items` as a
|
|
10
|
+
DOM property (`:items="…"` in Vue; the React wrapper and property assignment
|
|
11
|
+
do this naturally):
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const items: CTreeSelectItem[] = [
|
|
15
|
+
{
|
|
16
|
+
value: '1',
|
|
17
|
+
code: '1',
|
|
18
|
+
name: 'Natural sciences',
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
value: '111',
|
|
22
|
+
code: '111',
|
|
23
|
+
name: 'Mathematics',
|
|
24
|
+
children: [{ value: '1111', code: '1111', name: 'Pure mathematics' }],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A `disabled` branch cannot be entered and a `disabled` leaf cannot be
|
|
32
|
+
committed; both render as disabled rows, and the items below a disabled
|
|
33
|
+
branch are listed disabled in search results.
|
|
34
|
+
|
|
35
|
+
The value is the committed item's `value`, or `null` when nothing is
|
|
36
|
+
committed. With `return-object` the value is a fresh `{ value, name, code,
|
|
37
|
+
path }` object instead — `path` holds the item's ancestors root-first, each
|
|
38
|
+
as `{ value, name, code }` — never the `items` entry itself, and never its
|
|
39
|
+
children. The closed field shows the committed item's path on a muted line
|
|
40
|
+
above its code and name.
|
|
41
|
+
|
|
42
|
+
## Browsing and searching
|
|
43
|
+
|
|
44
|
+
The panel lists one level at a time: the top-level items first, then the
|
|
45
|
+
children of whichever branch is picked, with a breadcrumb above the list —
|
|
46
|
+
the root crumb ("All") followed by one crumb per ancestor — for climbing
|
|
47
|
+
back. The header names the level being chosen: give `level-labels` an array
|
|
48
|
+
of names, top level first ("Main field", "Field", "Subfield"), and it reads
|
|
49
|
+
"Choose Field"; a level without a name reads "Choose Level 2". While the
|
|
50
|
+
tree is evenly deep — every leaf at the same level — the header also counts
|
|
51
|
+
the steps ("Step 2 of 3"); in an unevenly deep tree the counter is left out,
|
|
52
|
+
and a level made only of leaves says "Final level" instead. Reopening the
|
|
53
|
+
panel returns to the committed item's level with its row selected, so its
|
|
54
|
+
siblings are one click away.
|
|
55
|
+
|
|
56
|
+
Typing into the search input switches the panel to a flat list of matches
|
|
57
|
+
from the whole tree, each with its path on a second line. The query is
|
|
58
|
+
matched case-insensitively anywhere in the name or code of an item and of
|
|
59
|
+
every ancestor above it, so a query matching a branch lists all of its
|
|
60
|
+
leaves. Supply a `filter` predicate to change the matching — it receives the
|
|
61
|
+
item, the query and the item's ancestors, and lists the item when it returns
|
|
62
|
+
`true`. Because `filter` is a function, it must be bound as a DOM property.
|
|
63
|
+
Deleting the query, or the "Browse instead" control in the header, returns to
|
|
64
|
+
the level the user was browsing.
|
|
65
|
+
|
|
66
|
+
While a query is typed, the runs of each row's code, label and path that
|
|
67
|
+
equal it are marked. The marks are the `match` part, the path line the `path`
|
|
68
|
+
part and the code column the `code` part:
|
|
69
|
+
|
|
70
|
+
```css
|
|
71
|
+
c-tree-select::part(match) {
|
|
72
|
+
font-weight: 600;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
From the keyboard, ArrowDown and ArrowUp move through the rows and Enter
|
|
77
|
+
activates one: a branch descends, a leaf commits. ArrowRight descends into a
|
|
78
|
+
highlighted branch and ArrowLeft — or Backspace with nothing left to delete —
|
|
79
|
+
climbs one level. Escape closes the panel and returns focus to the field; Tab
|
|
80
|
+
closes it and moves on.
|
|
81
|
+
|
|
82
|
+
## Committing a branch
|
|
83
|
+
|
|
84
|
+
By default only a leaf can be committed; a branch always opens its children.
|
|
85
|
+
Set `allow-branch` to let a branch be the value as well: every level below
|
|
86
|
+
the root then starts with a pinned select-branch row ("Select Natural
|
|
87
|
+
sciences") that commits the branch the user is in, and branches matching a
|
|
88
|
+
query are listed as search results and commit directly. The pinned row is the
|
|
89
|
+
`select-branch` part.
|
|
90
|
+
|
|
91
|
+
## Texts
|
|
92
|
+
|
|
93
|
+
Every built-in string — the root crumb, the header texts, a branch row's
|
|
94
|
+
child count, the select-branch row's label, the "Browse instead" control, the
|
|
95
|
+
no-results row, the search input's placeholder and accessible label, the
|
|
96
|
+
clear and toggle button labels — can be replaced for another language through
|
|
97
|
+
the `texts` object, merged over the English defaults. Interpolated texts are
|
|
98
|
+
functions, so the object must be bound as a DOM property; the `placeholder`
|
|
99
|
+
prop still wins over `texts.searchPlaceholder` when both are set:
|
|
100
|
+
|
|
101
|
+
```vue
|
|
102
|
+
<c-tree-select
|
|
103
|
+
:texts="{
|
|
104
|
+
root: 'Kaikki',
|
|
105
|
+
choose: (level) => `Valitse ${level}`,
|
|
106
|
+
children: (count) => `${count} alakohtaa`,
|
|
107
|
+
}"
|
|
108
|
+
/>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
To translate every tree select at once, set `texts` app-wide with
|
|
112
|
+
`applyDefaults({ 'c-tree-select': { texts } })` (Customization → App-wide
|
|
113
|
+
prop defaults); a per-instance `texts` still wins key by key.
|
|
114
|
+
|
|
115
|
+
## Scrolling
|
|
116
|
+
|
|
117
|
+
The panel shows `items-per-page` full rows (six by default) and then a
|
|
118
|
+
half-visible row instead of a scrollbar: the cut row is the cue that more
|
|
119
|
+
items follow, and the wheel, touch and arrow keys scroll as usual. Set
|
|
120
|
+
`items-per-page="0"` to let the list grow to the space the panel allows; it
|
|
121
|
+
still ends on a half row when it overflows. To bring the native scrollbar
|
|
122
|
+
back:
|
|
123
|
+
|
|
124
|
+
```css
|
|
125
|
+
c-tree-select::part(list) {
|
|
126
|
+
scrollbar-width: auto;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Narrow viewports
|
|
131
|
+
|
|
132
|
+
On a viewport narrower than 760px the panel opens as a **fullscreen panel**
|
|
133
|
+
instead of anchoring under the field: a heading row with the field's `label` and
|
|
134
|
+
a close button, the search input beneath it, then the items filling the rest of
|
|
135
|
+
the screen. The panel keeps covering the screen and the rows above the items
|
|
136
|
+
stay in view while the on-screen keyboard is open; the close button and Escape
|
|
137
|
+
both return focus to the field; the page behind the panel is inert until it
|
|
138
|
+
closes, and the list has no half-row cut — the screen edge is the cue. The
|
|
139
|
+
threshold is the viewport's width, never the field's, so a narrow field on a
|
|
140
|
+
desktop keeps its anchored panel. The close button's label is the `closePanel`
|
|
141
|
+
text, and the row's parts are `heading-row`, `heading` and `close`:
|
|
142
|
+
|
|
143
|
+
```css
|
|
144
|
+
c-tree-select::part(heading-row) {
|
|
145
|
+
border-bottom-color: var(--c-primary);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Lazily loaded trees
|
|
150
|
+
|
|
151
|
+
The component walks the `items` you give it and has no loading state of its
|
|
152
|
+
own: there is no `external` mode and no per-branch fetch event yet. A tree
|
|
153
|
+
that arrives in pieces can still be shown by re-assigning `items` with the
|
|
154
|
+
fetched `children` filled in — the panel keeps its level and re-homes the
|
|
155
|
+
highlight when the tree changes. A branch must already list its children to
|
|
156
|
+
be enterable, so load at least one level ahead of the user.
|