TrackTextSelectionMixin

Track the selection state of an inner input-like element

Overview

This mixin is an adjunct to WrappedStandardElement, intended to be used with a wrapped input or textarea. The inner input or textarea will have selection properties selectionStart and selectionEnd that we would like to track as state members. Doing so is challenging, because the browser provides no standard event tracking a change in selection.

To compensate, this mixin listens to keyboard or mouse activity within the inner element that might affect selection, then refreshes the host component's selection state as appropriate.