testimonials 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca7fa3a534c13036edc28e6206c06b5e4ef82949cafaeee614a2d196509c2176
4
- data.tar.gz: 140a7b0783d3284076def56a598a0c70bb72f1208b2a6158b62c09d634eeaeb2
3
+ metadata.gz: 64ae77e28152ded7574c56692bb5331588c89971c29822e6ef01d654667098bb
4
+ data.tar.gz: 74a32a67c21d0e26005d2caba5ea4fce687219b90ec9a0cd6d04f7d932ad6e25
5
5
  SHA512:
6
- metadata.gz: 6eebe2d3c06afff74b999f4a8a29120a97d3a2e78eeb0ff1429df26bf14a9303c66861665489fdb10104c9f7557bca3ad140f466ddb4a4b2a2116d465c3bc302
7
- data.tar.gz: 343195af39cd476f4a74728ab5e11997efa834806c7213aa3ab3b61bba933a6f2d89ccb6d255a9463b9089f9a4ebba5af078ff968db4b2adfff1fe1c6ad97cb3
6
+ metadata.gz: 23c1e3c61c49b77b5d39dd07b35479ffcf6b815a7d58c55de60a87a23e043c4871fc959ee888c130395dd82af4cb92793c8d1932ba5071026e5f9f13e693fbd0
7
+ data.tar.gz: 05f4489279978023649bcdf01c1a7421752a28221a73c22658442b83aae90ad584d50f04c034c41f0e1b816ff18ef694dd4009297403accaa9c0ab3b119a75c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4
4
+
5
+ - Validation and submit errors are announced to screen readers: every
6
+ `.tml-error` container is a `role="alert"` region from creation, and text
7
+ is inserted only after the region is exposed.
8
+ - Page scroll is locked behind the open widget dialog and restored on close;
9
+ a Turbo body swap that removes the overlay releases the lock too. The
10
+ inline collection-page form is unaffected.
11
+
3
12
  ## 0.1.3
4
13
 
5
14
  - Video playback no longer pauses itself moments after play in Firefox: the
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Testimonials
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -29,6 +29,7 @@
29
29
  var Z = 2147482000;
30
30
  var overlay = null;
31
31
  var lastFocused = null;
32
+ var savedOverflow = null; // documentElement overflow to restore when the modal closes
32
33
  var state = null; // one open session: { kind, auto, stage, rating, videoBlob, ... }
33
34
  var media = { stream: null, recorder: null, chunks: [], timer: null };
34
35
 
@@ -67,6 +68,10 @@
67
68
  config = readConfig() || config;
68
69
  injectStyles();
69
70
 
71
+ // A Turbo body swap can remove the overlay without close() running; the
72
+ // lock lives on documentElement, which survives the swap, so release it.
73
+ if (!document.getElementById("tml-overlay")) unlockScroll();
74
+
70
75
  if (config.mode === "page") {
71
76
  renderInline();
72
77
  return;
@@ -147,6 +152,7 @@
147
152
 
148
153
  overlay.appendChild(dialog);
149
154
  document.body.appendChild(overlay);
155
+ lockScroll();
150
156
  overlay.addEventListener("keydown", trapFocus);
151
157
 
152
158
  if (auto) postEvent(kind, "shown");
@@ -161,9 +167,21 @@
161
167
  overlay.remove();
162
168
  overlay = null;
163
169
  state = null;
170
+ unlockScroll();
164
171
  if (lastFocused && lastFocused.focus) lastFocused.focus();
165
172
  }
166
173
 
174
+ function lockScroll() {
175
+ if (savedOverflow === null) savedOverflow = document.documentElement.style.overflow;
176
+ document.documentElement.style.overflow = "hidden";
177
+ }
178
+
179
+ function unlockScroll() {
180
+ if (savedOverflow === null) return;
181
+ document.documentElement.style.overflow = savedOverflow;
182
+ savedOverflow = null;
183
+ }
184
+
167
185
  function dialogEl() {
168
186
  return overlay ? overlay.querySelector("#tml-dialog") : document.querySelector("[data-testimonials-inline] .tml-inline");
169
187
  }
@@ -301,6 +319,7 @@
301
319
  form.appendChild(consentField());
302
320
 
303
321
  var error = el("p", "tml-error");
322
+ error.setAttribute("role", "alert");
304
323
  error.hidden = true;
305
324
  form.appendChild(error);
306
325
 
@@ -470,6 +489,7 @@
470
489
  stage.appendChild(hint);
471
490
 
472
491
  var error = el("p", "tml-error");
492
+ error.setAttribute("role", "alert");
473
493
  error.hidden = true;
474
494
  stage.appendChild(error);
475
495
 
@@ -640,6 +660,7 @@
640
660
  stage.appendChild(playback);
641
661
 
642
662
  var error = el("p", "tml-error");
663
+ error.setAttribute("role", "alert");
643
664
  error.hidden = true;
644
665
  stage.appendChild(error);
645
666
 
@@ -747,6 +768,7 @@
747
768
  }
748
769
 
749
770
  var error = el("p", "tml-error");
771
+ error.setAttribute("role", "alert");
750
772
  error.hidden = true;
751
773
  form.appendChild(error);
752
774
 
@@ -952,8 +974,10 @@
952
974
  function showError(form, text) {
953
975
  var error = form.querySelector(".tml-error");
954
976
  if (!error) return;
955
- error.textContent = text;
977
+ // Unhide first: text landing in an already-exposed alert region is
978
+ // reliably announced; revealing role+text together sometimes isn't.
956
979
  error.hidden = false;
980
+ error.textContent = text;
957
981
  }
958
982
 
959
983
  // --- styles -------------------------------------------------------------------
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testimonials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shmarov