@placeholderco/placeholder-ui 3.2.8 → 3.3.1

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/index.d.ts CHANGED
@@ -60,6 +60,8 @@ export { default as AppShell } from './layout/AppShell.svelte';
60
60
  export type { AppShellProps } from './layout/AppShell.svelte';
61
61
  export { default as Sidenav } from './layout/Sidenav.svelte';
62
62
  export type { SidenavItem, SidenavItemAction, SidenavSection, SidenavProps } from './layout/Sidenav.svelte';
63
+ export { default as ResizeHandle } from './layout/ResizeHandle.svelte';
64
+ export type { ResizeHandleProps, ResizeHandleOrientation, ResizeHandleSide } from './layout/ResizeHandle.svelte';
63
65
  export { default as Paper } from './display/Paper.svelte';
64
66
  export type { PaperProps } from './display/Paper.svelte';
65
67
  export { default as Avatar } from './display/Avatar.svelte';
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ export { default as NavbarItemView } from './layout/NavbarItemView.svelte';
29
29
  export { default as CustomNavbar } from './layout/CustomNavbar.svelte';
30
30
  export { default as AppShell } from './layout/AppShell.svelte';
31
31
  export { default as Sidenav } from './layout/Sidenav.svelte';
32
+ export { default as ResizeHandle } from './layout/ResizeHandle.svelte';
32
33
  export { default as Paper } from './display/Paper.svelte';
33
34
  export { default as Avatar } from './display/Avatar.svelte';
34
35
  export { default as Autocomplete } from './form/Autocomplete.svelte';
@@ -0,0 +1,393 @@
1
+ <script lang="ts" module>
2
+ let panelCount = 0;
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { tick, untrack } from 'svelte';
7
+
8
+ export type ResizeHandleOrientation = 'vertical' | 'horizontal';
9
+ export type ResizeHandleSide = 'start' | 'end';
10
+
11
+ export interface ResizeHandleProps {
12
+ /** Panel size in px, or null to leave it to the layout (bindable) */
13
+ size?: number | null;
14
+ /** The element the handle resizes; measured, never styled (given an id if it has none) */
15
+ panel: HTMLElement | undefined;
16
+ /** Whether the panel is before ('start') or after ('end') the handle */
17
+ side?: ResizeHandleSide;
18
+ /** 'vertical' between columns (sets width) or 'horizontal' between rows (sets height) */
19
+ orientation?: ResizeHandleOrientation;
20
+ /** Minimum size (px) */
21
+ min?: number;
22
+ /** Maximum size (px); without one, the panel's container is the limit */
23
+ max?: number;
24
+ /** Size restored by double-click or Enter */
25
+ defaultSize?: number | null;
26
+ /** Distance per arrow key press (px); Shift moves four times as far */
27
+ step?: number;
28
+ /** Thickness of the grab area */
29
+ thickness?: string;
30
+ /** Accessible name for the handle */
31
+ ariaLabel: string;
32
+ /** Native tooltip text */
33
+ title?: string;
34
+ /** Disable dragging and keyboard resizing */
35
+ disabled?: boolean;
36
+ /** Callback on every size change, including each frame of a drag */
37
+ onresize?: (size: number | null) => void;
38
+ /** Callback once a drag, key press or reset settles the size */
39
+ onresizeend?: (size: number | null) => void;
40
+ /** Additional CSS classes */
41
+ class?: string;
42
+ }
43
+
44
+ let {
45
+ size = $bindable(null),
46
+ panel,
47
+ side = 'start',
48
+ orientation = 'vertical',
49
+ min = 0,
50
+ max = Infinity,
51
+ defaultSize = null,
52
+ step = 16,
53
+ thickness = '1rem',
54
+ ariaLabel,
55
+ title,
56
+ disabled = false,
57
+ onresize,
58
+ onresizeend,
59
+ class: className = ''
60
+ }: ResizeHandleProps = $props();
61
+
62
+ const vertical = $derived(orientation === 'vertical');
63
+
64
+ let handle: HTMLDivElement;
65
+ /** The panel's size as drawn, which a layout may hold below `size`. */
66
+ let drawn = $state(0);
67
+ /** The panel's container along the drag axis: the accessible maximum when `max` sets none. */
68
+ let room = $state(0);
69
+ let panelId = $state('');
70
+ let dragging = $state(false);
71
+ /** The one pointer driving the drag; any other (a second finger) is ignored. */
72
+ let activePointer: number | null = null;
73
+ let downAt = 0;
74
+ let moved = false;
75
+ /** The pointer's offset from the panel's edge when the drag began, so the edge doesn't jump. */
76
+ let grab = 0;
77
+ let pointer = 0;
78
+ let startSize: number | null = null;
79
+ let frame = 0;
80
+
81
+ const limit = $derived(Number.isFinite(max) ? max : Math.max(min, room));
82
+
83
+ $effect(() => {
84
+ const element = panel;
85
+ const alongX = vertical;
86
+ if (!element) return;
87
+ const container = element.parentElement;
88
+
89
+ const observer = new ResizeObserver(() => {
90
+ drawn = lengthOf(element, alongX);
91
+ if (container) room = lengthOf(container, alongX);
92
+ });
93
+ observer.observe(element);
94
+ if (container) observer.observe(container);
95
+ return () => observer.disconnect();
96
+ });
97
+
98
+ // aria-controls needs the panel's id; give it one only if it has none.
99
+ $effect(() => {
100
+ const element = panel;
101
+ if (!element) return;
102
+ if (element.id) {
103
+ panelId = element.id;
104
+ return;
105
+ }
106
+
107
+ const id = `pui-resize-panel-${++panelCount}`;
108
+ element.id = id;
109
+ panelId = id;
110
+ return () => {
111
+ if (element.id === id) element.removeAttribute('id');
112
+ };
113
+ });
114
+
115
+ // The page-wide cursor, and iframes made transparent to the pointer so they can't take the drag.
116
+ $effect(() => {
117
+ if (!dragging) return;
118
+ const root = document.documentElement;
119
+ const resizing = vertical ? 'pui-resizing-x' : 'pui-resizing-y';
120
+ root.classList.add(resizing);
121
+ return () => root.classList.remove(resizing);
122
+ });
123
+
124
+ $effect(() => {
125
+ if (disabled && dragging) untrack(() => void endDrag(false));
126
+ });
127
+
128
+ $effect(() => () => cancelAnimationFrame(frame));
129
+
130
+ function clamp(px: number): number {
131
+ return Math.round(Math.min(max, Math.max(min, px)));
132
+ }
133
+
134
+ function lengthOf(element: Element, alongX: boolean): number {
135
+ const rect = element.getBoundingClientRect();
136
+ return alongX ? rect.width : rect.height;
137
+ }
138
+
139
+ function coordinate(event: PointerEvent): number {
140
+ return vertical ? event.clientX : event.clientY;
141
+ }
142
+
143
+ /** Where the panel starts and ends along the drag axis. */
144
+ function extent(element: HTMLElement): [number, number] {
145
+ const rect = element.getBoundingClientRect();
146
+ return vertical ? [rect.left, rect.right] : [rect.top, rect.bottom];
147
+ }
148
+
149
+ function sizeAt(element: HTMLElement, position: number): number {
150
+ const [start, end] = extent(element);
151
+ const edge = position - grab;
152
+ return side === 'start' ? edge - start : end - edge;
153
+ }
154
+
155
+ function resetSize(): number | null {
156
+ return defaultSize === null ? null : clamp(defaultSize);
157
+ }
158
+
159
+ function update(next: number | null) {
160
+ if (next === size) return;
161
+ size = next;
162
+ onresize?.(next);
163
+ }
164
+
165
+ /** Applies a size, then reports the one drawn: a layout can hold the panel below what was asked. */
166
+ async function commit(next: number | null) {
167
+ update(next);
168
+ if (next === null) {
169
+ onresizeend?.(null);
170
+ return;
171
+ }
172
+
173
+ await tick();
174
+ const settled = panel ? clamp(lengthOf(panel, vertical)) : next;
175
+ update(settled);
176
+ onresizeend?.(settled);
177
+ }
178
+
179
+ function isActive(event: PointerEvent): boolean {
180
+ return dragging && event.pointerId === activePointer;
181
+ }
182
+
183
+ function handlePointerDown(event: PointerEvent) {
184
+ if (disabled || dragging || !panel || event.button !== 0) return;
185
+ event.preventDefault();
186
+ handle.focus();
187
+ handle.setPointerCapture(event.pointerId);
188
+
189
+ const [start, end] = extent(panel);
190
+ activePointer = event.pointerId;
191
+ pointer = downAt = coordinate(event);
192
+ grab = pointer - (side === 'start' ? end : start);
193
+ startSize = size;
194
+ moved = false;
195
+ dragging = true;
196
+ }
197
+
198
+ function handlePointerMove(event: PointerEvent) {
199
+ if (!isActive(event)) return;
200
+ pointer = coordinate(event);
201
+ moved ||= pointer !== downAt;
202
+ frame ||= requestAnimationFrame(() => {
203
+ frame = 0;
204
+ if (dragging && !disabled && panel) update(clamp(sizeAt(panel, pointer)));
205
+ });
206
+ }
207
+
208
+ function handlePointerEnd(event: PointerEvent) {
209
+ if (isActive(event)) void endDrag(true);
210
+ }
211
+
212
+ async function endDrag(keep: boolean) {
213
+ if (!dragging) return;
214
+ dragging = false;
215
+ cancelAnimationFrame(frame);
216
+ frame = 0;
217
+
218
+ const id = activePointer;
219
+ activePointer = null;
220
+ if (id !== null && handle?.hasPointerCapture(id)) handle.releasePointerCapture(id);
221
+
222
+ if (!keep) {
223
+ update(startSize);
224
+ return;
225
+ }
226
+ if (moved && panel) await commit(clamp(sizeAt(panel, pointer)));
227
+ }
228
+
229
+ function handleKeydown(event: KeyboardEvent) {
230
+ if (disabled) return;
231
+
232
+ if (event.key === 'Escape') {
233
+ if (dragging) {
234
+ event.preventDefault();
235
+ void endDrag(false);
236
+ }
237
+ return;
238
+ }
239
+ if (dragging) return;
240
+
241
+ // The keys move the handle, so a panel after it grows as the handle moves back.
242
+ const grow = side === 'start' ? 1 : -1;
243
+ const distance = (event.shiftKey ? step * 4 : step) * grow;
244
+ const current = panel ? lengthOf(panel, vertical) : drawn;
245
+ const back = vertical ? 'ArrowLeft' : 'ArrowUp';
246
+ const forward = vertical ? 'ArrowRight' : 'ArrowDown';
247
+ let next: number | null;
248
+
249
+ if (event.key === back) next = clamp(current - distance);
250
+ else if (event.key === forward) next = clamp(current + distance);
251
+ else if (event.key === 'Home') next = clamp(min);
252
+ else if (event.key === 'End') next = clamp(limit);
253
+ else if (event.key === 'Enter') next = resetSize();
254
+ else return;
255
+
256
+ event.preventDefault();
257
+ void commit(next);
258
+ }
259
+
260
+ function handleDoubleClick() {
261
+ if (!disabled && !dragging) void commit(resetSize());
262
+ }
263
+ </script>
264
+
265
+ <!-- A focusable separator is a widget (the WAI-ARIA window splitter); Svelte's rules see a static role. -->
266
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
267
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
268
+ <div
269
+ bind:this={handle}
270
+ class="pui-resize-handle {className}"
271
+ class:horizontal={!vertical}
272
+ class:dragging
273
+ class:disabled
274
+ style="--resize-handle-thickness: {thickness};"
275
+ role="separator"
276
+ aria-orientation={orientation}
277
+ aria-label={ariaLabel}
278
+ aria-controls={panelId || undefined}
279
+ aria-valuenow={Math.round(drawn)}
280
+ aria-valuemin={Math.round(min)}
281
+ aria-valuemax={Math.round(limit)}
282
+ aria-disabled={disabled || undefined}
283
+ tabindex={disabled ? -1 : 0}
284
+ {title}
285
+ onpointerdown={handlePointerDown}
286
+ onpointermove={handlePointerMove}
287
+ onpointerup={handlePointerEnd}
288
+ onpointercancel={handlePointerEnd}
289
+ onlostpointercapture={handlePointerEnd}
290
+ ondblclick={handleDoubleClick}
291
+ onkeydown={handleKeydown}
292
+ >
293
+ <span class="grip"></span>
294
+ </div>
295
+
296
+ <style>
297
+ /* A flex or grid item between the panels; it stretches to their length. */
298
+ .pui-resize-handle {
299
+ position: relative;
300
+ display: flex;
301
+ flex-direction: column;
302
+ align-items: center;
303
+ justify-content: center;
304
+ flex-shrink: 0;
305
+ align-self: stretch;
306
+ width: var(--resize-handle-thickness);
307
+ cursor: col-resize;
308
+ touch-action: none;
309
+ border-radius: var(--ui-radius-sm);
310
+ }
311
+
312
+ .pui-resize-handle.horizontal {
313
+ flex-direction: row;
314
+ width: auto;
315
+ height: var(--resize-handle-thickness);
316
+ cursor: row-resize;
317
+ }
318
+
319
+ /* The line the panel's edge follows. */
320
+ .pui-resize-handle::before {
321
+ content: '';
322
+ position: absolute;
323
+ top: 0;
324
+ bottom: 0;
325
+ left: calc(50% - 1px);
326
+ width: 2px;
327
+ border-radius: 999px;
328
+ transition: background-color 0.15s ease;
329
+ }
330
+
331
+ .pui-resize-handle.horizontal::before {
332
+ top: calc(50% - 1px);
333
+ bottom: auto;
334
+ left: 0;
335
+ right: 0;
336
+ width: auto;
337
+ height: 2px;
338
+ }
339
+
340
+ /* Sticky, so it stays in view beside a panel taller than the window. */
341
+ .grip {
342
+ position: sticky;
343
+ top: 1rem;
344
+ bottom: 1rem;
345
+ width: 0.25rem;
346
+ height: 2.5rem;
347
+ border-radius: 999px;
348
+ background-color: var(--placeholder-color);
349
+ transition: background-color 0.15s ease;
350
+ }
351
+
352
+ .horizontal .grip {
353
+ position: static;
354
+ width: 2.5rem;
355
+ height: 0.25rem;
356
+ }
357
+
358
+ .pui-resize-handle:not(.disabled):hover::before,
359
+ .pui-resize-handle:focus-visible::before,
360
+ .pui-resize-handle.dragging::before,
361
+ .pui-resize-handle:not(.disabled):hover .grip,
362
+ .pui-resize-handle:focus-visible .grip,
363
+ .pui-resize-handle.dragging .grip {
364
+ background-color: var(--ui-accent);
365
+ }
366
+
367
+ .pui-resize-handle:focus-visible {
368
+ outline: 2px solid var(--ui-focus-color);
369
+ outline-offset: -2px;
370
+ }
371
+
372
+ .pui-resize-handle.disabled {
373
+ cursor: default;
374
+ opacity: 0.5;
375
+ }
376
+
377
+ :global(html.pui-resizing-x),
378
+ :global(html.pui-resizing-x *) {
379
+ cursor: col-resize !important;
380
+ user-select: none;
381
+ }
382
+
383
+ :global(html.pui-resizing-y),
384
+ :global(html.pui-resizing-y *) {
385
+ cursor: row-resize !important;
386
+ user-select: none;
387
+ }
388
+
389
+ :global(html.pui-resizing-x iframe),
390
+ :global(html.pui-resizing-y iframe) {
391
+ pointer-events: none;
392
+ }
393
+ </style>
@@ -0,0 +1,37 @@
1
+ export type ResizeHandleOrientation = 'vertical' | 'horizontal';
2
+ export type ResizeHandleSide = 'start' | 'end';
3
+ export interface ResizeHandleProps {
4
+ /** Panel size in px, or null to leave it to the layout (bindable) */
5
+ size?: number | null;
6
+ /** The element the handle resizes; measured, never styled (given an id if it has none) */
7
+ panel: HTMLElement | undefined;
8
+ /** Whether the panel is before ('start') or after ('end') the handle */
9
+ side?: ResizeHandleSide;
10
+ /** 'vertical' between columns (sets width) or 'horizontal' between rows (sets height) */
11
+ orientation?: ResizeHandleOrientation;
12
+ /** Minimum size (px) */
13
+ min?: number;
14
+ /** Maximum size (px); without one, the panel's container is the limit */
15
+ max?: number;
16
+ /** Size restored by double-click or Enter */
17
+ defaultSize?: number | null;
18
+ /** Distance per arrow key press (px); Shift moves four times as far */
19
+ step?: number;
20
+ /** Thickness of the grab area */
21
+ thickness?: string;
22
+ /** Accessible name for the handle */
23
+ ariaLabel: string;
24
+ /** Native tooltip text */
25
+ title?: string;
26
+ /** Disable dragging and keyboard resizing */
27
+ disabled?: boolean;
28
+ /** Callback on every size change, including each frame of a drag */
29
+ onresize?: (size: number | null) => void;
30
+ /** Callback once a drag, key press or reset settles the size */
31
+ onresizeend?: (size: number | null) => void;
32
+ /** Additional CSS classes */
33
+ class?: string;
34
+ }
35
+ declare const ResizeHandle: import("svelte").Component<ResizeHandleProps, {}, "size">;
36
+ type ResizeHandle = ReturnType<typeof ResizeHandle>;
37
+ export default ResizeHandle;
@@ -14,7 +14,7 @@
14
14
  separator?: boolean;
15
15
  /** Right-aligned shortcut hint (e.g. `⌘C`, `Del`). Purely visual. */
16
16
  shortcut?: string;
17
- /** Nested submenu items — opens on hover. */
17
+ /** Nested submenu items — opens on hover, click, Enter/Space or ArrowRight. */
18
18
  children?: ContextMenuItem[];
19
19
  }
20
20
 
@@ -37,6 +37,7 @@
37
37
  </script>
38
38
 
39
39
  <script lang="ts">
40
+ import { tick } from 'svelte';
40
41
  import ContextMenuList from './ContextMenuList.svelte';
41
42
  import { topLayer } from '../util/Floating.js';
42
43
 
@@ -87,6 +88,32 @@
87
88
  placed = true;
88
89
  });
89
90
 
91
+ // Move focus into the menu once it is visible (hidden elements can't take focus), and hand it
92
+ // back to whatever had it before when the menu closes — however it closes. Keyed on `placed`
93
+ // rather than x/y so repositioning an open menu doesn't yank focus back to the first item.
94
+ $effect(() => {
95
+ if (!open || !placed || !menuEl) return;
96
+ const node = menuEl;
97
+ const previous = document.activeElement;
98
+ let active = true;
99
+ void tick().then(() => {
100
+ if (!active) return;
101
+ node
102
+ .querySelector<HTMLButtonElement>('button:not(:disabled)')
103
+ ?.focus({ preventScroll: true });
104
+ });
105
+ return () => {
106
+ active = false;
107
+ // Only restore if focus is still in (or was dropped by) the menu; an outside click
108
+ // that focused something else keeps that focus.
109
+ const current = document.activeElement;
110
+ const lost = !current || current === document.body || node.contains(current);
111
+ if (lost && previous instanceof HTMLElement && previous.isConnected) {
112
+ previous.focus({ preventScroll: true });
113
+ }
114
+ };
115
+ });
116
+
90
117
  // Dismiss the menu on outside interaction while it's open.
91
118
  $effect(() => {
92
119
  if (!open) return;
@@ -94,9 +121,16 @@
94
121
  if (menuEl && !menuEl.contains(e.target as Node)) close();
95
122
  };
96
123
  const onKey = (e: KeyboardEvent) => {
124
+ const target = e.target instanceof Element ? e.target : null;
125
+ const inMenu = !!(target && menuEl?.contains(target));
97
126
  if (e.key === 'Escape') {
127
+ // Inside a submenu, Escape closes just that level (handled by ContextMenuList).
128
+ if (inMenu && target?.closest('.pui-ctxmenu-submenu')) return;
98
129
  e.preventDefault();
99
130
  close();
131
+ } else if (e.key === 'Tab' && inMenu) {
132
+ // Let Tab proceed: focus is restored to the trigger first, so Tab moves on from there.
133
+ close();
100
134
  }
101
135
  };
102
136
  const onScroll = (e: Event) => {
@@ -13,7 +13,7 @@ export interface ContextMenuItem {
13
13
  separator?: boolean;
14
14
  /** Right-aligned shortcut hint (e.g. `⌘C`, `Del`). Purely visual. */
15
15
  shortcut?: string;
16
- /** Nested submenu items — opens on hover. */
16
+ /** Nested submenu items — opens on hover, click, Enter/Space or ArrowRight. */
17
17
  children?: ContextMenuItem[];
18
18
  }
19
19
  export interface ContextMenuProps {
@@ -3,6 +3,7 @@
3
3
  </script>
4
4
 
5
5
  <script lang="ts">
6
+ import { tick } from 'svelte';
6
7
  import Icon from '../icon/Icon.svelte';
7
8
  import { iconChevronRight } from '../icon/index.js';
8
9
  import Self from './ContextMenuList.svelte';
@@ -14,24 +15,94 @@
14
15
  /** Nesting level — only the top level applies `minWidth`. */
15
16
  depth?: number;
16
17
  minWidth?: string;
18
+ /** Set on submenus: closes this level and returns focus to its parent item. */
19
+ onBack?: () => void;
17
20
  }
18
21
 
19
- let { items, onSelect, depth = 0, minWidth = '' }: Props = $props();
22
+ let { items, onSelect, depth = 0, minWidth = '', onBack }: Props = $props();
23
+ let listEl = $state<HTMLUListElement | null>(null);
20
24
 
21
- // Only one submenu per list can be open at a time (the hovered item).
25
+ // Only one submenu per list can be open at a time.
22
26
  let hoverIndex = $state<number | null>(null);
23
27
  let submenuEl = $state<HTMLElement | null>(null);
24
28
  let flipLeft = $state(false);
25
29
 
26
- function onItemEnter(i: number, item: ContextMenuItem) {
30
+ const focusOpts = { preventScroll: true };
31
+
32
+ function onItemEnter(i: number, item: ContextMenuItem, li: HTMLElement) {
27
33
  hoverIndex = item.children?.length ? i : null;
34
+ // Keep focus with the pointer so a submenu closing under it never drops focus to <body>.
35
+ // Disabled rows can't take focus, so park it on the list itself.
36
+ const button = li.querySelector<HTMLButtonElement>(':scope > button');
37
+ (button && !button.disabled ? button : listEl)?.focus(focusOpts);
38
+ }
39
+
40
+ async function openSubmenu(i: number) {
41
+ hoverIndex = i;
42
+ await tick();
43
+ submenuEl?.querySelector<HTMLButtonElement>('button:not(:disabled)')?.focus(focusOpts);
28
44
  }
29
45
 
30
- function handleClick(item: ContextMenuItem) {
31
- if (item.disabled || item.separator || item.children?.length) return;
46
+ function closeSubmenu(i: number) {
47
+ hoverIndex = null;
48
+ listEl?.children.item(i)?.querySelector<HTMLButtonElement>(':scope > button')?.focus(focusOpts);
49
+ }
50
+
51
+ function handleClick(item: ContextMenuItem, i: number) {
52
+ if (item.disabled || item.separator) return;
53
+ if (item.children?.length) {
54
+ void openSubmenu(i);
55
+ return;
56
+ }
32
57
  onSelect(item);
33
58
  }
34
59
 
60
+ function onKey(event: KeyboardEvent) {
61
+ const target = event.target;
62
+ // Only handle keys aimed at this level (the list itself or one of its own items);
63
+ // nested lists handle their own.
64
+ if (
65
+ !listEl ||
66
+ !(target instanceof HTMLElement) ||
67
+ (target !== listEl && target.closest('[role="menu"]') !== listEl)
68
+ )
69
+ return;
70
+
71
+ const handled = () => {
72
+ event.preventDefault();
73
+ event.stopPropagation();
74
+ };
75
+
76
+ if (event.key === 'ArrowRight') {
77
+ const index = Array.from(listEl.children).indexOf(target.parentElement as Element);
78
+ if (!items[index]?.children?.length) return;
79
+ handled();
80
+ void openSubmenu(index);
81
+ return;
82
+ }
83
+ if ((event.key === 'ArrowLeft' || event.key === 'Escape') && onBack) {
84
+ handled();
85
+ onBack();
86
+ return;
87
+ }
88
+
89
+ const buttons = Array.from(
90
+ listEl.querySelectorAll<HTMLButtonElement>(':scope > li > button:not(:disabled)')
91
+ );
92
+ if (!buttons.length) return;
93
+ const last = buttons.length - 1;
94
+ const current = buttons.indexOf(target as HTMLButtonElement);
95
+ let next: number;
96
+ if (event.key === 'ArrowDown') next = current < 0 || current === last ? 0 : current + 1;
97
+ else if (event.key === 'ArrowUp') next = current <= 0 ? last : current - 1;
98
+ else if (event.key === 'Home') next = 0;
99
+ else if (event.key === 'End') next = last;
100
+ else return;
101
+ handled();
102
+ hoverIndex = null;
103
+ buttons[next].focus(focusOpts);
104
+ }
105
+
35
106
  // Decide whether the open submenu should flip to the left edge of its parent.
36
107
  // Measured from the parent <li> right edge so the result is stable once flipped.
37
108
  $effect(() => {
@@ -47,6 +118,9 @@
47
118
  <ul
48
119
  class="pui-ctxmenu-list"
49
120
  role="menu"
121
+ tabindex="-1"
122
+ bind:this={listEl}
123
+ onkeydown={onKey}
50
124
  style={depth === 0 && minWidth ? `min-width: ${minWidth};` : ''}
51
125
  >
52
126
  {#each items as item, i (i)}
@@ -54,14 +128,21 @@
54
128
  <li class="pui-ctxmenu-sep" role="separator"></li>
55
129
  {:else}
56
130
  <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
57
- <li class="pui-ctxmenu-li" role="none" onmouseenter={() => onItemEnter(i, item)}>
131
+ <li
132
+ class="pui-ctxmenu-li"
133
+ role="none"
134
+ onmouseenter={(e) => onItemEnter(i, item, e.currentTarget)}
135
+ >
58
136
  <button
59
137
  type="button"
60
138
  role="menuitem"
61
139
  class="pui-ctxmenu-item"
62
140
  class:danger={item.danger}
141
+ tabindex="-1"
142
+ aria-haspopup={item.children?.length ? 'menu' : undefined}
143
+ aria-expanded={item.children?.length ? hoverIndex === i : undefined}
63
144
  disabled={item.disabled}
64
- onclick={() => handleClick(item)}
145
+ onclick={() => handleClick(item, i)}
65
146
  >
66
147
  <span class="pui-ctxmenu-ico">
67
148
  {#if item.icon}<Icon svg={item.icon} size="1rem" />{/if}
@@ -77,7 +158,12 @@
77
158
 
78
159
  {#if item.children?.length && hoverIndex === i}
79
160
  <div class="pui-ctxmenu-submenu" class:flip-left={flipLeft} bind:this={submenuEl}>
80
- <Self items={item.children} {onSelect} depth={depth + 1} />
161
+ <Self
162
+ items={item.children}
163
+ {onSelect}
164
+ depth={depth + 1}
165
+ onBack={() => closeSubmenu(i)}
166
+ />
81
167
  </div>
82
168
  {/if}
83
169
  </li>
@@ -99,6 +185,10 @@
99
185
  user-select: none;
100
186
  }
101
187
 
188
+ .pui-ctxmenu-list:focus {
189
+ outline: none;
190
+ }
191
+
102
192
  .pui-ctxmenu-li {
103
193
  position: relative;
104
194
  }
@@ -6,6 +6,8 @@ interface Props {
6
6
  /** Nesting level — only the top level applies `minWidth`. */
7
7
  depth?: number;
8
8
  minWidth?: string;
9
+ /** Set on submenus: closes this level and returns focus to its parent item. */
10
+ onBack?: () => void;
9
11
  }
10
12
  declare const ContextMenuList: import("svelte").Component<Props, {}, "">;
11
13
  type ContextMenuList = ReturnType<typeof ContextMenuList>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placeholderco/placeholder-ui",
3
- "version": "3.2.8",
3
+ "version": "3.3.1",
4
4
  "description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
5
5
  "license": "MIT",
6
6
  "author": "Placeholderco",
@@ -78,11 +78,11 @@
78
78
  "prettier": "^3.9.10",
79
79
  "prettier-plugin-svelte": "^4.1.1",
80
80
  "publint": "^0.3.25",
81
- "rimraf": "^6.1.3",
81
+ "rimraf": "^6.1.4",
82
82
  "svelte": "^5.57.3",
83
83
  "svelte-check": "^4.7.8",
84
84
  "typescript": "^6.0.3",
85
- "vite": "^8.3.5"
85
+ "vite": "^8.3.6"
86
86
  },
87
87
  "dependencies": {
88
88
  "@codemirror/autocomplete": "^6.20.4",
@@ -101,23 +101,23 @@
101
101
  "@codemirror/theme-one-dark": "^6.1.3",
102
102
  "@codemirror/view": "^6.43.15",
103
103
  "@lezer/highlight": "^1.2.5",
104
- "@tiptap/core": "^3.32.2",
105
- "@tiptap/extension-bubble-menu": "^3.32.2",
106
- "@tiptap/extension-code-block": "^3.32.2",
107
- "@tiptap/extension-collaboration": "^3.32.2",
108
- "@tiptap/extension-collaboration-caret": "^3.32.2",
109
- "@tiptap/extension-color": "^3.32.2",
110
- "@tiptap/extension-image": "^3.32.2",
111
- "@tiptap/extension-link": "^3.32.2",
112
- "@tiptap/extension-placeholder": "^3.32.2",
113
- "@tiptap/extension-subscript": "^3.32.2",
114
- "@tiptap/extension-superscript": "^3.32.2",
115
- "@tiptap/extension-table": "^3.32.2",
116
- "@tiptap/extension-text-align": "^3.32.2",
117
- "@tiptap/extension-text-style": "^3.32.2",
118
- "@tiptap/extension-underline": "^3.32.2",
119
- "@tiptap/pm": "^3.32.2",
120
- "@tiptap/starter-kit": "^3.32.2",
104
+ "@tiptap/core": "^3.33.0",
105
+ "@tiptap/extension-bubble-menu": "^3.33.0",
106
+ "@tiptap/extension-code-block": "^3.33.0",
107
+ "@tiptap/extension-collaboration": "^3.33.0",
108
+ "@tiptap/extension-collaboration-caret": "^3.33.0",
109
+ "@tiptap/extension-color": "^3.33.0",
110
+ "@tiptap/extension-image": "^3.33.0",
111
+ "@tiptap/extension-link": "^3.33.0",
112
+ "@tiptap/extension-placeholder": "^3.33.0",
113
+ "@tiptap/extension-subscript": "^3.33.0",
114
+ "@tiptap/extension-superscript": "^3.33.0",
115
+ "@tiptap/extension-table": "^3.33.0",
116
+ "@tiptap/extension-text-align": "^3.33.0",
117
+ "@tiptap/extension-text-style": "^3.33.0",
118
+ "@tiptap/extension-underline": "^3.33.0",
119
+ "@tiptap/pm": "^3.33.0",
120
+ "@tiptap/starter-kit": "^3.33.0",
121
121
  "dayjs": "^1.11.23",
122
122
  "svelte-sonner": "^1.2.3",
123
123
  "yjs": "^13.6.33"