TanStack

KeyLockStateController

Defined in: controllers/key-lock-state.ts:37

A Lit ReactiveController that tracks whether a lock key, such as Caps Lock, is on.

Lock keys toggle instead of being held, so this reads the lock state that the browser reports on key and mouse events. Its value is null until the user presses a key, clicks, or moves the mouse, after the window loses focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS. Pass a getter to track a key that changes, such as a reactive property; it is read again on each host update.

Example

ts
class PasswordField extends LitElement {
  private capsLock = new KeyLockStateController(this, 'CapsLock')

  render() {
    return html`
      <label>
        Password
        <input type="password" />
        ${this.capsLock.value
          ? html`<span role="status">Caps Lock is on</span>`
          : null}
      </label>
    `
  }
}

Implements

  • ReactiveController

Constructors

Constructor

ts
new KeyLockStateController(_host, _key): KeyLockStateController;

Defined in: controllers/key-lock-state.ts:55

Parameters

_host

ReactiveControllerHost

The Lit component that owns this controller.

_key

MaybeGetter<LockKey>

'CapsLock', 'NumLock', or 'ScrollLock', or a getter.

Returns

KeyLockStateController

Accessors

value

Get Signature

ts
get value(): boolean | null;

Defined in: controllers/key-lock-state.ts:47

true when the lock is on, false when it is off, or null when the browser has not reported it.

Returns

boolean | null

Methods

dispose()

ts
dispose(): void;

Defined in: controllers/key-lock-state.ts:88

Releases the controller now and removes it from its host. Use it to remove a controller early: Lit's removeController alone leaves it active.

Returns

void


hostConnected()

ts
hostConnected(): void;

Defined in: controllers/key-lock-state.ts:62

Called when the host is connected to the component tree. For custom element hosts, this corresponds to the connectedCallback() lifecycle, which is only called when the component is connected to the document.

Returns

void

Implementation of

ts
ReactiveController.hostConnected

hostDisconnected()

ts
hostDisconnected(): void;

Defined in: controllers/key-lock-state.ts:78

Called when the host is disconnected from the component tree. For custom element hosts, this corresponds to the disconnectedCallback() lifecycle, which is called the host or an ancestor component is disconnected from the document.

Returns

void

Implementation of

ts
ReactiveController.hostDisconnected

hostUpdate()

ts
hostUpdate(): void;

Defined in: controllers/key-lock-state.ts:74

Re-reads a getter key when host properties trigger an update.

Returns

void

Implementation of

ts
ReactiveController.hostUpdate