focus method

void focus([
  1. UIEvent? event
])

Programmatically set focus on the underlying element, managing outline visibility depending on the type of event. The intended use case follows this general pattern:

<some-focusable-element keyboardOnlyFocusIndicator #focusTarget="keyboardOnlyFocusIndicator"> ... <button (trigger)="focusTarget.focus($event)">Focus!

Calling focus() on the element directly would cause its outline to show in response to clicks on the button, which is undesirable. Using this function, the outline is hidden in response to button clicks but shown in response to keypresses on the button.

Implementation

void focus([UIEvent? event]) {
  _domService.scheduleWrite(() {
    _element.focus();
  });
  if (event is MouseEvent) {
    hideOutline();
  } else {
    resetOutline();
  }
}