MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onFocus

Function onFocus

packages/react-aria/src/utils/keyboard.tsx:229–255  ·  view source on GitHub ↗
(e: FocusEvent)

Source from the content-addressed store, hash-verified

227}
228
229function onFocus(e: FocusEvent): void {
230 let target = getEventTarget(e);
231 let willKeyboardOpen = willOpenKeyboard(target as Element);
232
233 let time = performance.now();
234 let screen = getTouchScreen();
235
236 let delta = state.screenHeight - screen.height;
237
238 // Update the screen and start the timer if we are about to open.
239 if (delta < KEYBOARD_HEIGHT && willKeyboardOpen) {
240 state.screenWidth = screen.width;
241 state.screenHeight = screen.height;
242 state.screenAngle = screen.angle;
243 state.startTimeStamp = time;
244 }
245
246 // This focus will open a keyboard so reset the buffer.
247 if (willKeyboardOpen) {
248 window.clearTimeout(state.screenTimeout);
249 }
250
251 // Stop the timer if the keyboard is already open.
252 if (delta >= KEYBOARD_HEIGHT && willKeyboardOpen) {
253 state.endTimeStamp = time;
254 }
255}
256
257function setupGlobalEvents(): void {
258 let screen = getTouchScreen();

Callers

nothing calls this directly

Calls 3

getEventTargetFunction · 0.90
willOpenKeyboardFunction · 0.85
getTouchScreenFunction · 0.85

Tested by

no test coverage detected