| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary |
| 12 | */ |
| 13 | const supportedInputTypes: {[key: string]: true | void, ...} = { |
| 14 | color: true, |
| 15 | date: true, |
| 16 | datetime: true, |
| 17 | 'datetime-local': true, |
| 18 | email: true, |
| 19 | month: true, |
| 20 | number: true, |
| 21 | password: true, |
| 22 | range: true, |
| 23 | search: true, |
| 24 | tel: true, |
| 25 | text: true, |
| 26 | time: true, |
| 27 | url: true, |
| 28 | week: true, |
| 29 | }; |
| 30 | |
| 31 | function isTextInputElement(elem: ?HTMLElement): boolean { |
| 32 | const nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase(); |
| 33 | |
| 34 | if (nodeName === 'input') { |
| 35 | return !!supportedInputTypes[(elem as any as HTMLInputElement).type]; |
| 36 | } |
| 37 | |
| 38 | if (nodeName === 'textarea') { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | export default isTextInputElement; |