supportsSelectionRange function

bool supportsSelectionRange(
  1. InputElement element
)

Returns whether the provided element supports setSelectionRange.

Necessary in part because of the circular inheritance hierarchy in Dart's InputElement class structure, and in part because the classes do not correspond to whether setSelectionRange is supported (e.g. number inputs).

See: github.com/dart-lang/sdk/issues/22967

Implementation

bool supportsSelectionRange(InputElement element) {
  // Uncomment once https://github.com/dart-lang/sdk/issues/22967 is fixed.
  // if (element is TextInputElementBase) return true;

  final type = element.getAttribute('type');
  return inputTypesWithSelectionRangeSupport.contains(type);
}