dom.ts 616 B

12345678910111213141516171819
  1. export function isDOMElement(el: any): el is HTMLElement {
  2. return !!el && (el instanceof Element || el instanceof HTMLElement)
  3. }
  4. export function isTypableElement(el: HTMLElement): boolean {
  5. // If content editable, then it is editable
  6. if (el.isContentEditable) return true
  7. // If element is an input and the input is enabled, then it is typable
  8. if (el.tagName === "INPUT") {
  9. return !(el as HTMLInputElement).disabled
  10. }
  11. // If element is a textarea and the input is enabled, then it is typable
  12. if (el.tagName === "TEXTAREA") {
  13. return !(el as HTMLTextAreaElement).disabled
  14. }
  15. return false
  16. }