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

Function onPaste

packages/react-aria/src/numberfield/useNumberField.ts:238–255  ·  view source on GitHub ↗
(e: ClipboardEvent<HTMLInputElement>)

Source from the content-addressed store, hash-verified

236 };
237
238 let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {
239 props.onPaste?.(e);
240 let inputElement = getEventTarget(e) as HTMLInputElement;
241 // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated
242 // trying to calculate the new string based on what the paste is replacing and where in the source string it is
243 if (
244 inputElement &&
245 (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===
246 inputElement.value.length
247 ) {
248 e.preventDefault();
249 // commit so that the user gets to see what it formats to immediately
250 // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves
251 // spin button will then handle announcing the new value, this should work with controlled state as well
252 // because the announcement is done as a result of the new rendered input value if there is one
253 commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');
254 }
255 };
256
257 let domProps = filterDOMProps(props);
258 let onKeyDownEnter = useCallback(

Callers

nothing calls this directly

Calls 3

getEventTargetFunction · 0.90
getDataMethod · 0.80
commitFunction · 0.50

Tested by

no test coverage detected