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