MCPcopy Index your code
hub / github.com/react-component/input / triggerFocus

Function triggerFocus

src/utils/commonUtils.ts:98–124  ·  view source on GitHub ↗
(
  element?: HTMLInputElement | HTMLTextAreaElement,
  option?: InputFocusOptions,
)

Source from the content-addressed store, hash-verified

96}
97
98export 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}

Callers 2

focusFunction · 0.90
onInputClickFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…