( element?: HTMLInputElement | HTMLTextAreaElement, option?: InputFocusOptions, )
| 96 | } |
| 97 | |
| 98 | export function triggerFocus( |
| 99 | element?: HTMLInputElement | HTMLTextAreaElement, |
| 100 | option?: InputFocusOptions, |
| 101 | ) { |
| 102 | if (!element) return; |
| 103 | |
| 104 | element.focus(option); |
| 105 | |
| 106 | // Selection content |
| 107 | const { cursor } = option || {}; |
| 108 | if (cursor) { |
| 109 | const len = element.value.length; |
| 110 | |
| 111 | switch (cursor) { |
| 112 | case 'start': |
| 113 | element.setSelectionRange(0, 0); |
| 114 | break; |
| 115 | |
| 116 | case 'end': |
| 117 | element.setSelectionRange(len, len); |
| 118 | break; |
| 119 | |
| 120 | default: |
| 121 | element.setSelectionRange(0, len); |
| 122 | } |
| 123 | } |
| 124 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…