@iris-ui-kit/vue 0.2.5 → 0.2.7

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
@@ -390,11 +390,34 @@ var IrisNavMenu = vue.defineComponent({
390
390
  emit("update:expandedKeys", model.get());
391
391
  }
392
392
  };
393
+ const hovered = vue.ref(null);
394
+ const hoveredBranches = vue.ref([]);
395
+ const focusedBranches = vue.ref([]);
396
+ const closeHorizontalMenus = () => {
397
+ if (props.orientation !== "horizontal") return;
398
+ hovered.value = null;
399
+ hoveredBranches.value = [];
400
+ focusedBranches.value = [];
401
+ };
393
402
  const select = (node) => {
394
403
  if (node.disabled) return;
404
+ closeHorizontalMenus();
395
405
  emit("select", node.key, node);
396
406
  };
397
- const hovered = vue.ref(null);
407
+ const setBranchInteraction = (state, key, enabled) => {
408
+ const current = state.value;
409
+ if (enabled) {
410
+ if (!current.includes(key)) state.value = [...current, key];
411
+ } else if (current.includes(key)) {
412
+ state.value = current.filter((item) => item !== key);
413
+ }
414
+ };
415
+ const interactionKeyAtDepth = (keys, depth) => keys.find((key) => core.findNavPath(props.items, key).length === depth + 1);
416
+ const horizontalBranchVisible = (key, depth) => {
417
+ const hoveredAtDepth = interactionKeyAtDepth(hoveredBranches.value, depth);
418
+ if (hoveredAtDepth) return hoveredAtDepth === key;
419
+ return interactionKeyAtDepth(focusedBranches.value, depth) === key;
420
+ };
398
421
  const itemStyle = (opts) => {
399
422
  const bg = opts.active ? "var(--iris-primary)" : opts.hovered && !opts.disabled ? "var(--iris-surface)" : "transparent";
400
423
  return {
@@ -414,7 +437,7 @@ var IrisNavMenu = vue.defineComponent({
414
437
  cursor: opts.disabled ? "not-allowed" : "pointer",
415
438
  opacity: opts.disabled ? "0.5" : "1",
416
439
  padding: props.collapsed ? "10px" : "8px 10px",
417
- paddingInlineStart: props.collapsed ? "10px" : `${12 + opts.depth * 16}px`,
440
+ paddingInlineStart: props.collapsed || props.orientation === "horizontal" ? "10px" : `${12 + opts.depth * 16}px`,
418
441
  justifyContent: props.collapsed ? "center" : "flex-start"
419
442
  };
420
443
  };
@@ -473,6 +496,8 @@ var IrisNavMenu = vue.defineComponent({
473
496
  const renderItem = (node, depth) => {
474
497
  const branch = core.isBranch(node);
475
498
  const open = expanded.value.includes(node.key);
499
+ const horizontal = props.orientation === "horizontal";
500
+ const shown = horizontal ? horizontalBranchVisible(node.key, depth) : open;
476
501
  const active = node.key === props.activeKey;
477
502
  const trail = branch && !active && activePath.value.includes(node.key);
478
503
  const row = vue.h(
@@ -484,10 +509,10 @@ var IrisNavMenu = vue.defineComponent({
484
509
  "data-branch": branch ? "true" : void 0,
485
510
  "data-active": active ? "true" : void 0,
486
511
  "data-active-trail": trail ? "true" : void 0,
487
- "data-open": branch && open ? "true" : void 0,
512
+ "data-open": branch && shown ? "true" : void 0,
488
513
  "data-depth": String(depth),
489
514
  disabled: node.disabled,
490
- "aria-expanded": branch ? open ? "true" : "false" : void 0,
515
+ "aria-expanded": branch ? shown ? "true" : "false" : void 0,
491
516
  "aria-current": active ? "page" : void 0,
492
517
  style: itemStyle({
493
518
  depth,
@@ -515,14 +540,14 @@ var IrisNavMenu = vue.defineComponent({
515
540
  ),
516
541
  badgeNode(node),
517
542
  branch ? vue.h(IrisIcon, {
518
- name: open ? "chevron-down" : "chevron-right",
543
+ name: horizontal && depth === 0 ? "chevron-down" : "chevron-right",
519
544
  size: 16,
520
545
  style: { marginInlineStart: badgeNode(node) ? "6px" : "auto", opacity: "0.6" }
521
546
  }) : null
522
547
  ]
523
548
  );
524
- const groupStyle = props.orientation === "horizontal" && depth === 0 ? { position: "relative" } : void 0;
525
- if (!branch || !open)
549
+ const groupStyle = horizontal && branch ? { position: "relative" } : void 0;
550
+ if (!branch || !horizontal && !open)
526
551
  return vue.h(
527
552
  "div",
528
553
  { key: node.key, "data-iris-nav-group": branch ? "" : void 0, style: groupStyle },
@@ -530,7 +555,24 @@ var IrisNavMenu = vue.defineComponent({
530
555
  );
531
556
  return vue.h(
532
557
  "div",
533
- { key: node.key, "data-iris-nav-group": "", "data-open": "true", style: groupStyle },
558
+ {
559
+ key: node.key,
560
+ "data-iris-nav-group": "",
561
+ "data-open": shown ? "true" : void 0,
562
+ style: groupStyle,
563
+ ...horizontal ? {
564
+ onMouseenter: () => setBranchInteraction(hoveredBranches, node.key, true),
565
+ onMouseleave: () => setBranchInteraction(hoveredBranches, node.key, false),
566
+ onFocusin: () => setBranchInteraction(focusedBranches, node.key, true),
567
+ onFocusout: (event) => {
568
+ const group = event.currentTarget;
569
+ const next = event.relatedTarget;
570
+ if (!next || !group.contains(next)) {
571
+ setBranchInteraction(focusedBranches, node.key, false);
572
+ }
573
+ }
574
+ } : {}
575
+ },
534
576
  [
535
577
  row,
536
578
  vue.h(
@@ -538,11 +580,13 @@ var IrisNavMenu = vue.defineComponent({
538
580
  {
539
581
  "data-iris-nav-children": "",
540
582
  role: "group",
541
- style: props.orientation === "horizontal" && depth === 0 ? {
583
+ "aria-hidden": horizontal && !shown ? "true" : void 0,
584
+ style: horizontal ? {
585
+ display: shown ? "block" : "none",
542
586
  position: "absolute",
543
- insetBlockStart: "calc(100% + 4px)",
544
- insetInlineStart: "0",
545
- zIndex: "60",
587
+ insetBlockStart: depth === 0 ? "100%" : "0",
588
+ insetInlineStart: depth === 0 ? "0" : "100%",
589
+ zIndex: depth === 0 ? "60" : "61",
546
590
  minWidth: "220px",
547
591
  padding: "6px",
548
592
  border: "1px solid var(--iris-border)",
@@ -558,7 +602,9 @@ var IrisNavMenu = vue.defineComponent({
558
602
  };
559
603
  const onKeydown = (e) => {
560
604
  const root = e.currentTarget;
561
- const buttons = Array.from(root.querySelectorAll("[data-iris-nav-item]"));
605
+ const buttons = Array.from(root.querySelectorAll("[data-iris-nav-item]")).filter(
606
+ (button) => !button.closest('[data-iris-nav-children][aria-hidden="true"]')
607
+ );
562
608
  if (buttons.length === 0) return;
563
609
  const idx = buttons.indexOf(document.activeElement);
564
610
  const focusAt = (i) => buttons[(i + buttons.length) % buttons.length]?.focus();