@iris-ui-kit/vue 0.2.4 → 0.2.6

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/admin.cjs CHANGED
@@ -395,8 +395,24 @@ var IrisNavMenu = vue.defineComponent({
395
395
  emit("select", node.key, node);
396
396
  };
397
397
  const hovered = vue.ref(null);
398
+ const hoveredBranches = vue.ref([]);
399
+ const focusedBranches = vue.ref([]);
400
+ const setBranchInteraction = (state, key, enabled) => {
401
+ const current = state.value;
402
+ if (enabled) {
403
+ if (!current.includes(key)) state.value = [...current, key];
404
+ } else if (current.includes(key)) {
405
+ state.value = current.filter((item) => item !== key);
406
+ }
407
+ };
408
+ const interactionKeyAtDepth = (keys, depth) => keys.find((key) => core.findNavPath(props.items, key).length === depth + 1);
409
+ const horizontalBranchVisible = (key, depth) => {
410
+ const hoveredAtDepth = interactionKeyAtDepth(hoveredBranches.value, depth);
411
+ if (hoveredAtDepth) return hoveredAtDepth === key;
412
+ return interactionKeyAtDepth(focusedBranches.value, depth) === key;
413
+ };
398
414
  const itemStyle = (opts) => {
399
- const bg = opts.active ? "var(--iris-primary)" : hovered.value && !opts.disabled ? "var(--iris-surface)" : "transparent";
415
+ const bg = opts.active ? "var(--iris-primary)" : opts.hovered && !opts.disabled ? "var(--iris-surface)" : "transparent";
400
416
  return {
401
417
  display: "flex",
402
418
  alignItems: "center",
@@ -457,7 +473,13 @@ var IrisNavMenu = vue.defineComponent({
457
473
  title: node.title,
458
474
  "aria-label": branch ? `${node.title} (section)` : node.title,
459
475
  "aria-current": active && !branch ? "page" : void 0,
460
- style: itemStyle({ depth: 0, active, trail: false, disabled: !!node.disabled }),
476
+ style: itemStyle({
477
+ depth: 0,
478
+ active,
479
+ trail: false,
480
+ hovered: hovered.value === node.key,
481
+ disabled: !!node.disabled
482
+ }),
461
483
  ...hoverHandlers(node.key),
462
484
  onClick: () => select(branch ? core.firstLeaf(node) : node)
463
485
  },
@@ -467,8 +489,10 @@ var IrisNavMenu = vue.defineComponent({
467
489
  const renderItem = (node, depth) => {
468
490
  const branch = core.isBranch(node);
469
491
  const open = expanded.value.includes(node.key);
492
+ const horizontal = props.orientation === "horizontal";
493
+ const shown = horizontal ? horizontalBranchVisible(node.key, depth) : open;
470
494
  const active = node.key === props.activeKey;
471
- const trail = branch && activePath.value.includes(node.key);
495
+ const trail = branch && !active && activePath.value.includes(node.key);
472
496
  const row = vue.h(
473
497
  "button",
474
498
  {
@@ -477,12 +501,19 @@ var IrisNavMenu = vue.defineComponent({
477
501
  "data-key": node.key,
478
502
  "data-branch": branch ? "true" : void 0,
479
503
  "data-active": active ? "true" : void 0,
480
- "data-open": branch && open ? "true" : void 0,
504
+ "data-active-trail": trail ? "true" : void 0,
505
+ "data-open": branch && shown ? "true" : void 0,
481
506
  "data-depth": String(depth),
482
507
  disabled: node.disabled,
483
- "aria-expanded": branch ? open ? "true" : "false" : void 0,
508
+ "aria-expanded": branch ? shown ? "true" : "false" : void 0,
484
509
  "aria-current": active ? "page" : void 0,
485
- style: itemStyle({ depth, active, trail, disabled: !!node.disabled }),
510
+ style: itemStyle({
511
+ depth,
512
+ active,
513
+ trail,
514
+ hovered: hovered.value === node.key,
515
+ disabled: !!node.disabled
516
+ }),
486
517
  ...hoverHandlers(node.key),
487
518
  onClick: () => branch ? toggle(node.key) : select(node)
488
519
  },
@@ -502,14 +533,14 @@ var IrisNavMenu = vue.defineComponent({
502
533
  ),
503
534
  badgeNode(node),
504
535
  branch ? vue.h(IrisIcon, {
505
- name: open ? "chevron-down" : "chevron-right",
536
+ name: horizontal ? "chevron-down" : "chevron-right",
506
537
  size: 16,
507
538
  style: { marginInlineStart: badgeNode(node) ? "6px" : "auto", opacity: "0.6" }
508
539
  }) : null
509
540
  ]
510
541
  );
511
- const groupStyle = props.orientation === "horizontal" && depth === 0 ? { position: "relative" } : void 0;
512
- if (!branch || !open)
542
+ const groupStyle = horizontal && depth === 0 ? { position: "relative" } : void 0;
543
+ if (!branch || !horizontal && !open)
513
544
  return vue.h(
514
545
  "div",
515
546
  { key: node.key, "data-iris-nav-group": branch ? "" : void 0, style: groupStyle },
@@ -517,7 +548,24 @@ var IrisNavMenu = vue.defineComponent({
517
548
  );
518
549
  return vue.h(
519
550
  "div",
520
- { key: node.key, "data-iris-nav-group": "", "data-open": "true", style: groupStyle },
551
+ {
552
+ key: node.key,
553
+ "data-iris-nav-group": "",
554
+ "data-open": shown ? "true" : void 0,
555
+ style: groupStyle,
556
+ ...horizontal ? {
557
+ onMouseenter: () => setBranchInteraction(hoveredBranches, node.key, true),
558
+ onMouseleave: () => setBranchInteraction(hoveredBranches, node.key, false),
559
+ onFocusin: () => setBranchInteraction(focusedBranches, node.key, true),
560
+ onFocusout: (event) => {
561
+ const group = event.currentTarget;
562
+ const next = event.relatedTarget;
563
+ if (!next || !group.contains(next)) {
564
+ setBranchInteraction(focusedBranches, node.key, false);
565
+ }
566
+ }
567
+ } : {}
568
+ },
521
569
  [
522
570
  row,
523
571
  vue.h(
@@ -525,9 +573,11 @@ var IrisNavMenu = vue.defineComponent({
525
573
  {
526
574
  "data-iris-nav-children": "",
527
575
  role: "group",
528
- style: props.orientation === "horizontal" && depth === 0 ? {
576
+ "aria-hidden": horizontal && !shown ? "true" : void 0,
577
+ style: horizontal && depth === 0 ? {
578
+ display: shown ? "block" : "none",
529
579
  position: "absolute",
530
- insetBlockStart: "calc(100% + 4px)",
580
+ insetBlockStart: "100%",
531
581
  insetInlineStart: "0",
532
582
  zIndex: "60",
533
583
  minWidth: "220px",
@@ -536,7 +586,7 @@ var IrisNavMenu = vue.defineComponent({
536
586
  borderRadius: "var(--iris-radius-md, 6px)",
537
587
  background: "var(--iris-surface)",
538
588
  boxShadow: "var(--iris-shadow-md)"
539
- } : void 0
589
+ } : horizontal ? { display: shown ? "block" : "none" } : void 0
540
590
  },
541
591
  (node.children ?? []).map((child) => renderItem(child, depth + 1))
542
592
  )
@@ -545,7 +595,11 @@ var IrisNavMenu = vue.defineComponent({
545
595
  };
546
596
  const onKeydown = (e) => {
547
597
  const root = e.currentTarget;
548
- const buttons = Array.from(root.querySelectorAll("[data-iris-nav-item]"));
598
+ const buttons = Array.from(
599
+ root.querySelectorAll("[data-iris-nav-item]")
600
+ ).filter(
601
+ (button) => !button.closest('[data-iris-nav-children][aria-hidden="true"]')
602
+ );
549
603
  if (buttons.length === 0) return;
550
604
  const idx = buttons.indexOf(document.activeElement);
551
605
  const focusAt = (i) => buttons[(i + buttons.length) % buttons.length]?.focus();