2013-10-09 01:26:51 +08:00
|
|
|
/**
|
2018-09-08 06:11:23 +08:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2013-10-09 01:26:51 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2013-10-09 01:26:51 +08:00
|
|
|
*
|
2016-07-06 01:22:56 +08:00
|
|
|
* @flow
|
2013-10-09 01:26:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2014-01-15 20:47:16 +08:00
|
|
|
* @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
|
2013-10-09 01:26:51 +08:00
|
|
|
*/
|
2017-12-01 08:03:27 +08:00
|
|
|
const supportedInputTypes: {[key: string]: true | void} = {
|
2017-03-14 08:05:18 +08:00
|
|
|
color: true,
|
|
|
|
|
date: true,
|
|
|
|
|
datetime: true,
|
2013-10-09 01:26:51 +08:00
|
|
|
'datetime-local': true,
|
2017-03-14 08:05:18 +08:00
|
|
|
email: true,
|
|
|
|
|
month: true,
|
|
|
|
|
number: true,
|
|
|
|
|
password: true,
|
|
|
|
|
range: true,
|
|
|
|
|
search: true,
|
|
|
|
|
tel: true,
|
|
|
|
|
text: true,
|
|
|
|
|
time: true,
|
|
|
|
|
url: true,
|
|
|
|
|
week: true,
|
2013-10-09 01:26:51 +08:00
|
|
|
};
|
|
|
|
|
|
2016-09-03 08:35:14 +08:00
|
|
|
function isTextInputElement(elem: ?HTMLElement): boolean {
|
2017-12-01 08:03:27 +08:00
|
|
|
const nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
|
2016-07-06 01:22:56 +08:00
|
|
|
|
|
|
|
|
if (nodeName === 'input') {
|
|
|
|
|
return !!supportedInputTypes[((elem: any): HTMLInputElement).type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nodeName === 'textarea') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2013-10-09 01:26:51 +08:00
|
|
|
}
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
export default isTextInputElement;
|