UNPKG

@testing-library/user-event

Version:
52 lines (49 loc) 2.28 kB
import '../click/isClickableInput.js'; import '../dataTransfer/Clipboard.js'; import { getContentEditable } from '../edit/isContentEditable.js'; import '../edit/maxLength.js'; import { editableInputTypes } from '../edit/isEditable.js'; import '@testing-library/dom'; import { isElementType } from '../misc/isElementType.js'; import { setSelection } from './selection.js'; import '@testing-library/dom/dist/helpers.js'; import '../keyDef/readNextDescriptor.js'; import '../misc/level.js'; import '../../options.js'; import '../../event/eventMap.js'; import '../../event/behavior/click.js'; import '../../event/behavior/cut.js'; import '../../event/behavior/keydown.js'; import '../../event/behavior/keypress.js'; import '../../event/behavior/keyup.js'; import '../../event/behavior/paste.js'; import { getUISelection } from '../../document/selection.js'; import { getUIValue } from '../../document/value.js'; /** * Expand a selection like the browser does when pressing Ctrl+A. */ function selectAll(target) { if (isElementType(target, 'textarea') || isElementType(target, 'input') && target.type in editableInputTypes) { return setSelection({ focusNode: target, anchorOffset: 0, focusOffset: getUIValue(target).length }); } var ref; const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body; setSelection({ focusNode, anchorOffset: 0, focusOffset: focusNode.childNodes.length }); } function isAllSelected(target) { if (isElementType(target, 'textarea') || isElementType(target, 'input') && target.type in editableInputTypes) { return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length; } var ref; const focusNode = (ref = getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body; const selection = target.ownerDocument.getSelection(); return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length; } export { isAllSelected, selectAll };