@jobber/components 6.31.0 → 6.31.1

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/Chip-cjs.js CHANGED
@@ -22,7 +22,7 @@ var styles = {"wrapper":"NLNJBhRffp4-","input":"ulLzwMsQL3U-","inactive":"_3LLjp
22
22
 
23
23
  function InternalChipButton({ icon, invalid, disabled, label, onClick, }) {
24
24
  const buttonRef = React.useRef();
25
- return (React.createElement("div", { ref: buttonRef, className: styles.button, tabIndex: 0, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, onClick: handleClick, role: "button", "aria-label": `Remove ${label}`, "aria-hidden": true, "aria-disabled": disabled, "data-testid": "remove-chip-button" },
25
+ return (React.createElement("div", { ref: buttonRef, className: styles.button, tabIndex: 0, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, onClick: handleClick, role: "button", "aria-label": `Remove ${label}`, "aria-hidden": disabled, "aria-disabled": disabled, "data-testid": "remove-chip-button" },
26
26
  React.createElement(Icon.Icon, { size: "small", name: icon, color: getColor() })));
27
27
  function handleKeyUp(event) {
28
28
  if (document.activeElement === buttonRef.current &&
package/dist/Chip-es.js CHANGED
@@ -20,7 +20,7 @@ var styles = {"wrapper":"NLNJBhRffp4-","input":"ulLzwMsQL3U-","inactive":"_3LLjp
20
20
 
21
21
  function InternalChipButton({ icon, invalid, disabled, label, onClick, }) {
22
22
  const buttonRef = useRef();
23
- return (React__default.createElement("div", { ref: buttonRef, className: styles.button, tabIndex: 0, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, onClick: handleClick, role: "button", "aria-label": `Remove ${label}`, "aria-hidden": true, "aria-disabled": disabled, "data-testid": "remove-chip-button" },
23
+ return (React__default.createElement("div", { ref: buttonRef, className: styles.button, tabIndex: 0, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, onClick: handleClick, role: "button", "aria-label": `Remove ${label}`, "aria-hidden": disabled, "aria-disabled": disabled, "data-testid": "remove-chip-button" },
24
24
  React__default.createElement(Icon, { size: "small", name: icon, color: getColor() })));
25
25
  function handleKeyUp(event) {
26
26
  if (document.activeElement === buttonRef.current &&
@@ -290,6 +290,25 @@ function createAnnouncedElement() {
290
290
  return el;
291
291
  }
292
292
 
293
+ /**
294
+ * Recursively finds a focusable element (div or button) in the specified direction
295
+ */
296
+ function findFocusableElement(element, direction) {
297
+ if (!element)
298
+ return null;
299
+ const nextElement = direction === "previous"
300
+ ? element.previousElementSibling
301
+ : element.nextElementSibling;
302
+ if (!nextElement)
303
+ return null;
304
+ // Check if element is a div or button
305
+ if (nextElement instanceof HTMLElement &&
306
+ (nextElement.tagName === "DIV" || nextElement.tagName === "BUTTON")) {
307
+ return nextElement;
308
+ }
309
+ // Recursively continue search
310
+ return findFocusableElement(nextElement, direction);
311
+ }
293
312
  function useInternalChipDismissible({ children, selected, onChange, onClick, onCustomAdd, }) {
294
313
  const ref = React.useRef(null);
295
314
  const chipOptions = children.map(chip => chip.props);
@@ -316,15 +335,17 @@ function useInternalChipDismissible({ children, selected, onChange, onClick, onC
316
335
  const isInputAndHasValue = target instanceof HTMLInputElement && target.value;
317
336
  if (isInputAndHasValue)
318
337
  return;
319
- const nextElementToFocus = target.nextElementSibling;
320
- const prevElementToFocus = target.previousElementSibling;
321
- if (event.key === "ArrowLeft" &&
322
- prevElementToFocus instanceof HTMLElement) {
323
- prevElementToFocus.focus();
338
+ if (event.key === "ArrowLeft") {
339
+ const prevFocusable = findFocusableElement(target, "previous");
340
+ if (prevFocusable) {
341
+ prevFocusable.focus();
342
+ }
324
343
  }
325
- if (event.key === "ArrowRight" &&
326
- nextElementToFocus instanceof HTMLElement) {
327
- nextElementToFocus.focus();
344
+ if (event.key === "ArrowRight") {
345
+ const nextFocusable = findFocusableElement(target, "next");
346
+ if (nextFocusable) {
347
+ nextFocusable.focus();
348
+ }
328
349
  }
329
350
  },
330
351
  handleChipKeyDown: (value) => {
@@ -332,13 +353,13 @@ function useInternalChipDismissible({ children, selected, onChange, onClick, onC
332
353
  if (event.key === "Backspace" || event.key === "Delete") {
333
354
  const target = event.target;
334
355
  if (target instanceof HTMLElement) {
335
- const prevElement = target.previousElementSibling;
336
- const nextElement = target.nextElementSibling;
337
- if (prevElement instanceof HTMLElement) {
338
- prevElement.focus();
356
+ const prevFocusable = findFocusableElement(target, "previous");
357
+ const nextFocusable = findFocusableElement(target, "next");
358
+ if (prevFocusable) {
359
+ prevFocusable.focus();
339
360
  }
340
- else if (nextElement instanceof HTMLElement) {
341
- nextElement.focus();
361
+ else if (nextFocusable) {
362
+ nextFocusable.focus();
342
363
  }
343
364
  }
344
365
  actions.handleChipRemove(value)();
@@ -288,6 +288,25 @@ function createAnnouncedElement() {
288
288
  return el;
289
289
  }
290
290
 
291
+ /**
292
+ * Recursively finds a focusable element (div or button) in the specified direction
293
+ */
294
+ function findFocusableElement(element, direction) {
295
+ if (!element)
296
+ return null;
297
+ const nextElement = direction === "previous"
298
+ ? element.previousElementSibling
299
+ : element.nextElementSibling;
300
+ if (!nextElement)
301
+ return null;
302
+ // Check if element is a div or button
303
+ if (nextElement instanceof HTMLElement &&
304
+ (nextElement.tagName === "DIV" || nextElement.tagName === "BUTTON")) {
305
+ return nextElement;
306
+ }
307
+ // Recursively continue search
308
+ return findFocusableElement(nextElement, direction);
309
+ }
291
310
  function useInternalChipDismissible({ children, selected, onChange, onClick, onCustomAdd, }) {
292
311
  const ref = useRef(null);
293
312
  const chipOptions = children.map(chip => chip.props);
@@ -314,15 +333,17 @@ function useInternalChipDismissible({ children, selected, onChange, onClick, onC
314
333
  const isInputAndHasValue = target instanceof HTMLInputElement && target.value;
315
334
  if (isInputAndHasValue)
316
335
  return;
317
- const nextElementToFocus = target.nextElementSibling;
318
- const prevElementToFocus = target.previousElementSibling;
319
- if (event.key === "ArrowLeft" &&
320
- prevElementToFocus instanceof HTMLElement) {
321
- prevElementToFocus.focus();
336
+ if (event.key === "ArrowLeft") {
337
+ const prevFocusable = findFocusableElement(target, "previous");
338
+ if (prevFocusable) {
339
+ prevFocusable.focus();
340
+ }
322
341
  }
323
- if (event.key === "ArrowRight" &&
324
- nextElementToFocus instanceof HTMLElement) {
325
- nextElementToFocus.focus();
342
+ if (event.key === "ArrowRight") {
343
+ const nextFocusable = findFocusableElement(target, "next");
344
+ if (nextFocusable) {
345
+ nextFocusable.focus();
346
+ }
326
347
  }
327
348
  },
328
349
  handleChipKeyDown: (value) => {
@@ -330,13 +351,13 @@ function useInternalChipDismissible({ children, selected, onChange, onClick, onC
330
351
  if (event.key === "Backspace" || event.key === "Delete") {
331
352
  const target = event.target;
332
353
  if (target instanceof HTMLElement) {
333
- const prevElement = target.previousElementSibling;
334
- const nextElement = target.nextElementSibling;
335
- if (prevElement instanceof HTMLElement) {
336
- prevElement.focus();
354
+ const prevFocusable = findFocusableElement(target, "previous");
355
+ const nextFocusable = findFocusableElement(target, "next");
356
+ if (prevFocusable) {
357
+ prevFocusable.focus();
337
358
  }
338
- else if (nextElement instanceof HTMLElement) {
339
- nextElement.focus();
359
+ else if (nextFocusable) {
360
+ nextFocusable.focus();
340
361
  }
341
362
  }
342
363
  actions.handleChipRemove(value)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "6.31.0",
3
+ "version": "6.31.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -490,5 +490,5 @@
490
490
  "> 1%",
491
491
  "IE 10"
492
492
  ],
493
- "gitHead": "01b07bb9befa08500981551d32fd7c54d2f7dfe3"
493
+ "gitHead": "fc7b94413203d2412defd168c6e765e3fd114f8a"
494
494
  }