Skip to content

Commit

Permalink
documentHasSelection: Accept any input types
Browse files Browse the repository at this point in the history
... as oppposed to just text inputs (isTextField) and number inputs
(isNumberInput).
  • Loading branch information
mcsf committed Apr 19, 2022
1 parent d99e21b commit b301855
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ _Returns_

### documentHasSelection

Check whether the current document has a selection. This checks for both
focus in an input field and general text selection.
Check whether the current document has a selection. This includes focus in
input fields, textareas, and general rich-text selection.

_Parameters_

Expand Down
10 changes: 5 additions & 5 deletions packages/dom/src/dom/document-has-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* Internal dependencies
*/
import isTextField from './is-text-field';
import isNumberInput from './is-number-input';
import isHTMLInputElement from './is-html-input-element';
import documentHasTextSelection from './document-has-text-selection';

/**
* Check whether the current document has a selection. This checks for both
* focus in an input field and general text selection.
* Check whether the current document has a selection. This includes focus in
* input fields, textareas, and general rich-text selection.
*
* @param {Document} doc The document to check.
*
Expand All @@ -16,8 +16,8 @@ import documentHasTextSelection from './document-has-text-selection';
export default function documentHasSelection( doc ) {
return (
!! doc.activeElement &&
( isTextField( doc.activeElement ) ||
isNumberInput( doc.activeElement ) ||
( isHTMLInputElement( doc.activeElement ) ||
isTextField( doc.activeElement ) ||
documentHasTextSelection( doc ) )
);
}

0 comments on commit b301855

Please sign in to comment.