@rokkit/actions 1.0.5 → 1.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/actions",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "Contains generic actions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/navigator.js CHANGED
@@ -211,8 +211,30 @@ export class Navigator {
211
211
  if (!key) return
212
212
  const el = /** @type {HTMLElement|null} */ (this.#root.querySelector(`[data-path="${key}"]`))
213
213
  if (!el) return
214
- if (el !== document.activeElement) el.focus()
215
- el.scrollIntoView?.({ block: 'nearest', inline: 'nearest' })
214
+ // preventScroll stops the browser from cascading the focus call
215
+ // up the ancestor chain and scrolling outer containers.
216
+ if (el !== document.activeElement) el.focus({ preventScroll: true })
217
+ this.#scrollItemIntoView(el)
218
+ }
219
+
220
+ /**
221
+ * Scroll `el` into view *within `this.#root`* only — never walk ancestors.
222
+ * This prevents page-jumping when the navigator's root is itself inside
223
+ * a scrollable container (e.g. a Select dropdown inside a scrollable
224
+ * canvas-body).
225
+ * @param {HTMLElement} el
226
+ */
227
+ #scrollItemIntoView(el) {
228
+ const root = this.#root
229
+ const itemTop = el.offsetTop
230
+ const itemBottom = itemTop + el.offsetHeight
231
+ const visibleTop = root.scrollTop
232
+ const visibleBottom = visibleTop + root.clientHeight
233
+ if (itemTop < visibleTop) {
234
+ root.scrollTop = itemTop
235
+ } else if (itemBottom > visibleBottom) {
236
+ root.scrollTop = itemBottom - root.clientHeight
237
+ }
216
238
  }
217
239
 
218
240
  // ─── Typeahead ───────────────────────────────────────────────────────────
@@ -41,6 +41,20 @@ export function themable(root, options) {
41
41
  root.dataset.mode = theme.mode
42
42
  root.dataset.density = theme.density
43
43
 
44
+ // Mirror onto documentElement too. The flash-prevention init script
45
+ // sets `html.dataset.*` before body parses; without this mirror,
46
+ // runtime mode/style changes write to `body` only and the html
47
+ // element retains its initial values. CSS rules using bare
48
+ // `[data-mode='dark']` (no element prefix) match via ancestors,
49
+ // so both the old html value and the new body value would apply,
50
+ // causing the partial / no-op style change users see when toggling.
51
+ if (typeof document !== 'undefined' && root !== document.documentElement) {
52
+ const el = document.documentElement
53
+ el.dataset.style = theme.style
54
+ el.dataset.mode = theme.mode
55
+ el.dataset.density = theme.density
56
+ }
57
+
44
58
  // if (storageKey) theme.save(storageKey)
45
59
  })
46
60
  }