plossy 0.2.1 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Plossy v0.2.1 | MIT License
2
+ * Plossy v0.3.0 | MIT License
3
3
  *
4
4
  * Includes icons from Lucide (https://lucide.dev), some of them derived from Feather.
5
5
  * Full third-party notices (also shipped as LICENSE-LUCIDE):
@@ -1308,6 +1308,8 @@ var Upload = class extends Component {
1308
1308
  this.input.type = "file";
1309
1309
  this.input.tabIndex = -1;
1310
1310
  this.input.name = options.name;
1311
+ this.input.setAttribute("aria-label", "Wybierz pliki");
1312
+ this.input.hidden = true;
1311
1313
  el.append(this.input);
1312
1314
  if (!el.hasAttribute("tabindex")) el.tabIndex = 0;
1313
1315
  el.setAttribute("role", "button");
@@ -3051,6 +3053,10 @@ var Datepicker = class extends Component {
3051
3053
  this.picker.hidden = true;
3052
3054
  this.picker.setAttribute("role", "dialog");
3053
3055
  this.picker.setAttribute("aria-label", this.labels.dialog);
3056
+ if (!this.picker.id) this.picker.id = uid("pl-datepicker");
3057
+ this.ownRole = this.isInput && !el.hasAttribute("role");
3058
+ if (this.ownRole) el.setAttribute("role", "combobox");
3059
+ el.setAttribute("aria-controls", this.picker.id);
3054
3060
  el.setAttribute("aria-haspopup", "dialog");
3055
3061
  el.setAttribute("aria-expanded", "false");
3056
3062
  el.autocomplete = "off";
@@ -3063,6 +3069,8 @@ var Datepicker = class extends Component {
3063
3069
  if (!this.inline) {
3064
3070
  el.removeAttribute("aria-haspopup");
3065
3071
  el.removeAttribute("aria-expanded");
3072
+ el.removeAttribute("aria-controls");
3073
+ if (this.ownRole) el.removeAttribute("role");
3066
3074
  }
3067
3075
  });
3068
3076
  }
@@ -4633,6 +4641,10 @@ var Tooltip = class extends Component {
4633
4641
  }
4634
4642
  this.labelled = false;
4635
4643
  if (options.title && !options.html && !el.hasAttribute("aria-label") && !el.hasAttribute("aria-labelledby") && !el.textContent.trim() && !el.matches("input, select, textarea")) {
4644
+ if (!el.hasAttribute("role") && !el.matches("a[href], button, summary, img, svg")) {
4645
+ el.setAttribute("role", "img");
4646
+ this.onDestroy(() => el.removeAttribute("role"));
4647
+ }
4636
4648
  el.setAttribute("aria-label", String(options.title));
4637
4649
  this.labelled = true;
4638
4650
  }
@@ -4769,8 +4781,11 @@ var Popover = class extends Component {
4769
4781
  else if (!options.title) options.title = native;
4770
4782
  el.removeAttribute("title");
4771
4783
  }
4772
- el.setAttribute("aria-haspopup", "dialog");
4773
- el.setAttribute("aria-expanded", "false");
4784
+ this.expandable = !el.matches("input, select, textarea");
4785
+ if (this.expandable) {
4786
+ el.setAttribute("aria-haspopup", "dialog");
4787
+ el.setAttribute("aria-expanded", "false");
4788
+ }
4774
4789
  if (!el.matches("button, a[href], input, select, textarea, [tabindex]")) {
4775
4790
  el.setAttribute("role", "button");
4776
4791
  el.tabIndex = 0;
@@ -4947,7 +4962,7 @@ var Popover = class extends Component {
4947
4962
  pop.classList.remove("pl-leave");
4948
4963
  pop.classList.add("pl-open");
4949
4964
  el.classList.add("pl-open");
4950
- el.setAttribute("aria-expanded", "true");
4965
+ if (this.expandable) el.setAttribute("aria-expanded", "true");
4951
4966
  if (options.mode === "click") el.setAttribute("aria-controls", pop.id);
4952
4967
  else el.setAttribute("aria-describedby", pop.id);
4953
4968
  showLayer(pop);
@@ -4976,7 +4991,7 @@ var Popover = class extends Component {
4976
4991
  const index = open2.indexOf(this);
4977
4992
  if (index > -1) open2.splice(index, 1);
4978
4993
  el.classList.remove("pl-open");
4979
- el.setAttribute("aria-expanded", "false");
4994
+ if (this.expandable) el.setAttribute("aria-expanded", "false");
4980
4995
  el.removeAttribute("aria-describedby");
4981
4996
  if (hadFocus || refocus === true && this.options.mode === "click") {
4982
4997
  this.suppressFocus = true;
@@ -6608,6 +6623,9 @@ var Switcher = class extends Component {
6608
6623
  el.setAttribute("role", "tablist");
6609
6624
  if (this.vertical) el.setAttribute("aria-orientation", "vertical");
6610
6625
  else el.removeAttribute("aria-orientation");
6626
+ for (const child of el.children) {
6627
+ if (!items.includes(child) && !child.hasAttribute("role")) child.setAttribute("role", "presentation");
6628
+ }
6611
6629
  }
6612
6630
  const containers2 = this.containers;
6613
6631
  items.forEach((item, i) => {
@@ -7683,7 +7701,7 @@ var Carousel = class extends Component {
7683
7701
  this.generatedNavs.add(nav);
7684
7702
  const current2 = [...nav.children].map((li) => li.getAttribute(this.attr)).join();
7685
7703
  if (current2 !== indexes.join()) {
7686
- nav.innerHTML = indexes.map((i) => `<li ${this.attr}="${i}"><a href="#" role="button">${L.goto} ${i + 1}</a></li>`).join("");
7704
+ nav.innerHTML = indexes.map((i) => `<li ${this.attr}="${i}"><a href="#" role="button" aria-label="${L.goto} ${i + 1}"></a></li>`).join("");
7687
7705
  }
7688
7706
  } else {
7689
7707
  [...nav.children].forEach((item, i) => {
@@ -8969,9 +8987,15 @@ var Filter = class extends Component {
8969
8987
  this.apply(control);
8970
8988
  });
8971
8989
  this.on(this.el, "keydown", (event) => {
8972
- if (event.key !== "Enter" && event.key !== " " || !event.target.matches?.(`${CONTROL}[role="button"]`)) return;
8973
- event.preventDefault();
8974
- this.apply(event.target);
8990
+ if (event.key !== "Enter" && event.key !== " ") return;
8991
+ const target = event.target;
8992
+ if (target.matches?.(`${CONTROL}[role="button"]`)) {
8993
+ event.preventDefault();
8994
+ this.apply(target);
8995
+ } else if (event.key === " " && target.matches?.('a[role="button"]') && target.closest(CONTROL)) {
8996
+ event.preventDefault();
8997
+ this.apply(target.closest(CONTROL));
8998
+ }
8975
8999
  });
8976
9000
  this.onDestroy(() => this.finishAnimations());
8977
9001
  this.setState(this.state, false);
@@ -9034,7 +9058,9 @@ var Filter = class extends Component {
9034
9058
  const active2 = this.isActive(control);
9035
9059
  control.classList.toggle("pl-active", active2);
9036
9060
  const button = control.matches('a, button, [role="button"]') ? control : control.querySelector("a, button");
9037
- button?.setAttribute("aria-pressed", String(active2));
9061
+ if (!button) continue;
9062
+ if (button.matches("a") && !button.hasAttribute("role")) button.setAttribute("role", "button");
9063
+ button.setAttribute("aria-pressed", String(active2));
9038
9064
  }
9039
9065
  this.finishAnimations();
9040
9066
  const animation = animate && !prefersReducedMotion() && this.options.duration > 0 ? this.options.animation : false;
package/dist/plossy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Plossy v0.2.1 | MIT License
2
+ * Plossy v0.3.0 | MIT License
3
3
  *
4
4
  * Includes icons from Lucide (https://lucide.dev), some of them derived from Feather.
5
5
  * Full third-party notices (also shipped as LICENSE-LUCIDE):
@@ -1309,6 +1309,8 @@
1309
1309
  this.input.type = "file";
1310
1310
  this.input.tabIndex = -1;
1311
1311
  this.input.name = options.name;
1312
+ this.input.setAttribute("aria-label", "Wybierz pliki");
1313
+ this.input.hidden = true;
1312
1314
  el.append(this.input);
1313
1315
  if (!el.hasAttribute("tabindex")) el.tabIndex = 0;
1314
1316
  el.setAttribute("role", "button");
@@ -3052,6 +3054,10 @@
3052
3054
  this.picker.hidden = true;
3053
3055
  this.picker.setAttribute("role", "dialog");
3054
3056
  this.picker.setAttribute("aria-label", this.labels.dialog);
3057
+ if (!this.picker.id) this.picker.id = uid("pl-datepicker");
3058
+ this.ownRole = this.isInput && !el.hasAttribute("role");
3059
+ if (this.ownRole) el.setAttribute("role", "combobox");
3060
+ el.setAttribute("aria-controls", this.picker.id);
3055
3061
  el.setAttribute("aria-haspopup", "dialog");
3056
3062
  el.setAttribute("aria-expanded", "false");
3057
3063
  el.autocomplete = "off";
@@ -3064,6 +3070,8 @@
3064
3070
  if (!this.inline) {
3065
3071
  el.removeAttribute("aria-haspopup");
3066
3072
  el.removeAttribute("aria-expanded");
3073
+ el.removeAttribute("aria-controls");
3074
+ if (this.ownRole) el.removeAttribute("role");
3067
3075
  }
3068
3076
  });
3069
3077
  }
@@ -4634,6 +4642,10 @@
4634
4642
  }
4635
4643
  this.labelled = false;
4636
4644
  if (options.title && !options.html && !el.hasAttribute("aria-label") && !el.hasAttribute("aria-labelledby") && !el.textContent.trim() && !el.matches("input, select, textarea")) {
4645
+ if (!el.hasAttribute("role") && !el.matches("a[href], button, summary, img, svg")) {
4646
+ el.setAttribute("role", "img");
4647
+ this.onDestroy(() => el.removeAttribute("role"));
4648
+ }
4637
4649
  el.setAttribute("aria-label", String(options.title));
4638
4650
  this.labelled = true;
4639
4651
  }
@@ -4770,8 +4782,11 @@
4770
4782
  else if (!options.title) options.title = native;
4771
4783
  el.removeAttribute("title");
4772
4784
  }
4773
- el.setAttribute("aria-haspopup", "dialog");
4774
- el.setAttribute("aria-expanded", "false");
4785
+ this.expandable = !el.matches("input, select, textarea");
4786
+ if (this.expandable) {
4787
+ el.setAttribute("aria-haspopup", "dialog");
4788
+ el.setAttribute("aria-expanded", "false");
4789
+ }
4775
4790
  if (!el.matches("button, a[href], input, select, textarea, [tabindex]")) {
4776
4791
  el.setAttribute("role", "button");
4777
4792
  el.tabIndex = 0;
@@ -4948,7 +4963,7 @@
4948
4963
  pop.classList.remove("pl-leave");
4949
4964
  pop.classList.add("pl-open");
4950
4965
  el.classList.add("pl-open");
4951
- el.setAttribute("aria-expanded", "true");
4966
+ if (this.expandable) el.setAttribute("aria-expanded", "true");
4952
4967
  if (options.mode === "click") el.setAttribute("aria-controls", pop.id);
4953
4968
  else el.setAttribute("aria-describedby", pop.id);
4954
4969
  showLayer(pop);
@@ -4977,7 +4992,7 @@
4977
4992
  const index = open2.indexOf(this);
4978
4993
  if (index > -1) open2.splice(index, 1);
4979
4994
  el.classList.remove("pl-open");
4980
- el.setAttribute("aria-expanded", "false");
4995
+ if (this.expandable) el.setAttribute("aria-expanded", "false");
4981
4996
  el.removeAttribute("aria-describedby");
4982
4997
  if (hadFocus || refocus === true && this.options.mode === "click") {
4983
4998
  this.suppressFocus = true;
@@ -6609,6 +6624,9 @@
6609
6624
  el.setAttribute("role", "tablist");
6610
6625
  if (this.vertical) el.setAttribute("aria-orientation", "vertical");
6611
6626
  else el.removeAttribute("aria-orientation");
6627
+ for (const child of el.children) {
6628
+ if (!items.includes(child) && !child.hasAttribute("role")) child.setAttribute("role", "presentation");
6629
+ }
6612
6630
  }
6613
6631
  const containers2 = this.containers;
6614
6632
  items.forEach((item, i) => {
@@ -7684,7 +7702,7 @@
7684
7702
  this.generatedNavs.add(nav);
7685
7703
  const current2 = [...nav.children].map((li) => li.getAttribute(this.attr)).join();
7686
7704
  if (current2 !== indexes.join()) {
7687
- nav.innerHTML = indexes.map((i) => `<li ${this.attr}="${i}"><a href="#" role="button">${L.goto} ${i + 1}</a></li>`).join("");
7705
+ nav.innerHTML = indexes.map((i) => `<li ${this.attr}="${i}"><a href="#" role="button" aria-label="${L.goto} ${i + 1}"></a></li>`).join("");
7688
7706
  }
7689
7707
  } else {
7690
7708
  [...nav.children].forEach((item, i) => {
@@ -8970,9 +8988,15 @@
8970
8988
  this.apply(control);
8971
8989
  });
8972
8990
  this.on(this.el, "keydown", (event) => {
8973
- if (event.key !== "Enter" && event.key !== " " || !event.target.matches?.(`${CONTROL}[role="button"]`)) return;
8974
- event.preventDefault();
8975
- this.apply(event.target);
8991
+ if (event.key !== "Enter" && event.key !== " ") return;
8992
+ const target = event.target;
8993
+ if (target.matches?.(`${CONTROL}[role="button"]`)) {
8994
+ event.preventDefault();
8995
+ this.apply(target);
8996
+ } else if (event.key === " " && target.matches?.('a[role="button"]') && target.closest(CONTROL)) {
8997
+ event.preventDefault();
8998
+ this.apply(target.closest(CONTROL));
8999
+ }
8976
9000
  });
8977
9001
  this.onDestroy(() => this.finishAnimations());
8978
9002
  this.setState(this.state, false);
@@ -9035,7 +9059,9 @@
9035
9059
  const active2 = this.isActive(control);
9036
9060
  control.classList.toggle("pl-active", active2);
9037
9061
  const button = control.matches('a, button, [role="button"]') ? control : control.querySelector("a, button");
9038
- button?.setAttribute("aria-pressed", String(active2));
9062
+ if (!button) continue;
9063
+ if (button.matches("a") && !button.hasAttribute("role")) button.setAttribute("role", "button");
9064
+ button.setAttribute("aria-pressed", String(active2));
9039
9065
  }
9040
9066
  this.finishAnimations();
9041
9067
  const animation = animate && !prefersReducedMotion() && this.options.duration > 0 ? this.options.animation : false;