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

Method onFocus

packages/react-aria/src/dnd/DragManager.ts:269–308  ·  view source on GitHub ↗
(e: FocusEvent)

Source from the content-addressed store, hash-verified

267 }
268
269 onFocus(e: FocusEvent): void {
270 let activateButton = this.getCurrentActivateButton();
271 let eventTarget = getEventTarget(e);
272 if (eventTarget === activateButton) {
273 // TODO: canceling this breaks the focus ring. Revisit when we support tabbing.
274 this.cancelEvent(e);
275 return;
276 }
277
278 // Prevent focus events, except to the original drag target.
279 if (eventTarget !== this.dragTarget.element) {
280 this.cancelEvent(e);
281 }
282
283 // Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.
284 if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {
285 return;
286 }
287
288 let dropTarget =
289 this.validDropTargets.find(target => target.element === eventTarget) ||
290 this.validDropTargets.find(target => nodeContains(target.element, eventTarget));
291
292 if (!dropTarget) {
293 // if (e.target === activateButton) {
294 // activateButton.focus();
295 // }
296 if (this.currentDropTarget) {
297 this.currentDropTarget.element.focus();
298 } else {
299 this.dragTarget.element.focus();
300 }
301 return;
302 }
303
304 let item = dropItems.get(eventTarget);
305 if (dropTarget) {
306 this.setCurrentDropTarget(dropTarget, item);
307 }
308 }
309
310 onBlur(e: FocusEvent): void {
311 let activateButton = this.getCurrentActivateButton();

Callers 6

onFocusFunction · 0.80
onFocusFunction · 0.80
useDateRangePickerFunction · 0.80
onFocusWithinFunction · 0.80
useDatePickerFunction · 0.80

Calls 6

cancelEventMethod · 0.95
setCurrentDropTargetMethod · 0.95
getEventTargetFunction · 0.90
nodeContainsFunction · 0.90
focusMethod · 0.80

Tested by

no test coverage detected