@getflip/swirl-components 0.120.1 → 0.120.2

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.
@@ -1,7 +1,7 @@
1
1
  import { h, Host, } from "@stencil/core";
2
2
  import classnames from "classnames";
3
- import { getDesktopMediaQuery } from "../../utils";
4
3
  import { v4 as uuid } from "uuid";
4
+ import { getDesktopMediaQuery } from "../../utils";
5
5
  /**
6
6
  * @slot control - Used to add a menu button to the item
7
7
  * @slot badges - Badges displayed inside the item
@@ -22,6 +22,12 @@ export class SwirlResourceListItem {
22
22
  this.checked = !this.checked;
23
23
  this.valueChange.emit(this.checked);
24
24
  };
25
+ this.onBlur = () => {
26
+ this.makeControlUnfocusable();
27
+ };
28
+ this.onFocus = () => {
29
+ this.makeControlFocusable();
30
+ };
25
31
  this.onMenuTriggerClick = (event) => {
26
32
  if (this.disabled && !Boolean(this.href)) {
27
33
  event.stopPropagation();
@@ -61,6 +67,7 @@ export class SwirlResourceListItem {
61
67
  this.forceIconProps(this.desktopMediaQuery.matches);
62
68
  this.updateIconSize(this.desktopMediaQuery.matches);
63
69
  this.desktopMediaQuery.onchange = this.desktopMediaQueryHandler;
70
+ this.makeControlUnfocusable();
64
71
  if (Boolean(this.menuTriggerId)) {
65
72
  console.warn('[Swirl] The "menu-trigger-id" prop of swirl-resource-list-item is deprecated and will be removed with the next major release. Please use the "control" slot to add a menu button instead. https://swirl-storybook.flip-app.dev/?path=/docs/components-swirlresourcelistitem--docs');
66
73
  }
@@ -82,6 +89,23 @@ export class SwirlResourceListItem {
82
89
  this.hasMedia = hasMedia;
83
90
  }
84
91
  }
92
+ getControl() {
93
+ return this.el.querySelector('[slot="control"] button');
94
+ }
95
+ makeControlFocusable() {
96
+ const control = this.getControl();
97
+ if (!Boolean(control)) {
98
+ return;
99
+ }
100
+ control.tabIndex = 0;
101
+ }
102
+ makeControlUnfocusable() {
103
+ const control = this.getControl();
104
+ if (!Boolean(control)) {
105
+ return;
106
+ }
107
+ control.tabIndex = -1;
108
+ }
85
109
  render() {
86
110
  const Tag = !this.interactive && !this.selectable
87
111
  ? "div"
@@ -110,7 +134,7 @@ export class SwirlResourceListItem {
110
134
  "resource-list-item--show-control-on-focus": showControlOnFocus,
111
135
  "resource-list-item--show-meta": showMeta,
112
136
  });
113
- return (h(Host, { role: "row" }, h("div", { class: className, role: "gridcell" }, h(Tag, { "aria-checked": ariaChecked, "aria-disabled": disabled ? "true" : undefined, "aria-labelledby": this.id, class: "resource-list-item__content", href: href, disabled: disabled, onClick: this.onClick, part: "resource-list-item__content", role: role, tabIndex: 0, type: Tag === "button" ? "button" : undefined }, this.hasMedia && (h("span", { class: "resource-list-item__media" }, h("slot", { name: "media" }))), h("span", { class: "resource-list-item__label-container" }, h("span", { class: "resource-list-item__label", id: this.id, innerHTML: this.label }), this.description && (h("span", { class: "resource-list-item__description" }, this.description))), showMeta && (h("span", { class: "resource-list-item__meta" }, h("span", { class: "resource-list-item__meta-text" }, this.meta), h("span", { class: "resource-list-item__badges" }, h("slot", { name: "badges" }))))), this.selectable && (h("span", { "aria-hidden": "true", class: "resource-list-item__checkbox" }, h("span", { class: "resource-list-item__checkbox-icon" }, this.checked && (h("swirl-icon-check-strong", null))))), h("span", { class: "resource-list-item__control" }, h("slot", { name: "control" })), showMenu && (h("swirl-popover-trigger", { popover: this.menuTriggerId }, h("swirl-button", { "aria-disabled": disabled ? "true" : undefined, class: "resource-list-item__menu-trigger", disabled: disabled, hideLabel: true, icon: "<swirl-icon-more-horizontal></swirl-icon-more-horizontal>", intent: "primary", label: this.menuTriggerLabel, onClick: this.onMenuTriggerClick })))), this.allowDrag && (h("button", { "aria-describedby": this.dragHandleDescription, "aria-label": `${this.dragHandleLabel} "${this.label}"`, class: "resource-list-item__drag-handle", onKeyDown: this.onDragHandleKeyDown, type: "button" }, h("swirl-icon-drag-handle", { size: this.iconSize })))));
137
+ return (h(Host, { role: "row" }, h("div", { class: className, role: "gridcell" }, h(Tag, { "aria-checked": ariaChecked, "aria-disabled": disabled ? "true" : undefined, "aria-labelledby": this.id, class: "resource-list-item__content", href: href, disabled: disabled, onClick: this.onClick, onBlur: this.onBlur, onFocus: this.onFocus, part: "resource-list-item__content", role: role, tabIndex: 0, type: Tag === "button" ? "button" : undefined }, this.hasMedia && (h("span", { class: "resource-list-item__media" }, h("slot", { name: "media" }))), h("span", { class: "resource-list-item__label-container" }, h("span", { class: "resource-list-item__label", id: this.id, innerHTML: this.label }), this.description && (h("span", { class: "resource-list-item__description" }, this.description))), showMeta && (h("span", { class: "resource-list-item__meta" }, h("span", { class: "resource-list-item__meta-text" }, this.meta), h("span", { class: "resource-list-item__badges" }, h("slot", { name: "badges" }))))), this.selectable && (h("span", { "aria-hidden": "true", class: "resource-list-item__checkbox" }, h("span", { class: "resource-list-item__checkbox-icon" }, this.checked && (h("swirl-icon-check-strong", null))))), h("span", { class: "resource-list-item__control" }, h("slot", { name: "control" })), showMenu && (h("swirl-popover-trigger", { popover: this.menuTriggerId }, h("swirl-button", { "aria-disabled": disabled ? "true" : undefined, class: "resource-list-item__menu-trigger", disabled: disabled, hideLabel: true, icon: "<swirl-icon-more-horizontal></swirl-icon-more-horizontal>", intent: "primary", label: this.menuTriggerLabel, onClick: this.onMenuTriggerClick })))), this.allowDrag && (h("button", { "aria-describedby": this.dragHandleDescription, "aria-label": `${this.dragHandleLabel} "${this.label}"`, class: "resource-list-item__drag-handle", onKeyDown: this.onDragHandleKeyDown, type: "button" }, h("swirl-icon-drag-handle", { size: this.iconSize })))));
114
138
  }
115
139
  static get is() { return "swirl-resource-list-item"; }
116
140
  static get encapsulation() { return "scoped"; }