()
| 71 | |
| 72 | // Focus the first placeholder segment from the end on mouse down/touch up in the field. |
| 73 | let focusLast = () => { |
| 74 | if (!ref.current) { |
| 75 | return; |
| 76 | } |
| 77 | // Try to find the segment prior to the element that was clicked on. |
| 78 | let target = window.event ? (getEventTarget(window.event) as FocusableElement) : null; |
| 79 | let walker = getFocusableTreeWalker(ref.current, {tabbable: true}); |
| 80 | if (target) { |
| 81 | walker.currentNode = target; |
| 82 | target = walker.previousNode() as FocusableElement; |
| 83 | } |
| 84 | |
| 85 | // If no target found, find the last element from the end. |
| 86 | if (!target) { |
| 87 | let last: FocusableElement; |
| 88 | do { |
| 89 | last = walker.lastChild() as FocusableElement; |
| 90 | if (last) { |
| 91 | target = last; |
| 92 | } |
| 93 | } while (last); |
| 94 | } |
| 95 | |
| 96 | // Now go backwards until we find an element that is not a placeholder. |
| 97 | while (target?.hasAttribute('data-placeholder')) { |
| 98 | let prev = walker.previousNode() as FocusableElement; |
| 99 | if (prev && prev.hasAttribute('data-placeholder')) { |
| 100 | target = prev; |
| 101 | } else { |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (target) { |
| 107 | target.focus(); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | let {pressProps} = usePress({ |
| 112 | preventFocusOnPress: true, |
no test coverage detected