Skip to content

Latest commit

 

History

History
75 lines (44 loc) · 1.84 KB

focus-target.md

File metadata and controls

75 lines (44 loc) · 1.84 KB
layout tags
doc-api.html
internal, argument-list

ally.get.focusTarget

Identifies the element that would get focus upon click

Description

When clicking on the <span> element, focus is given to the <div>, because it's the first focusable parent element.

<div tabindex="-1">
  <p>Hello <span>World</span>!</p>
</div>

When clicking on the <label> element, focus is given to the <input>, because it's the referenced form control.

<label for="world">Hello</label>
<input id="world" type="text">

Usage

var element = ally.get.focusTarget({
  context: '#element-to-start-from',
});

Arguments

Name Type Default Description
context <selector> required The element to start searching from. The first element of a collection is used.
except <focus identification exception> {} The Element to test.

Returns

HTMLElement.

Throws

TypeError if context option is not specified.

Examples

Changes

  • Since v1.1.0 elements redirecting focus return their target elements.
  • Since v1.1.0 exceptions can be passed through to ally.is.focusable via the except argument.

Notes

See ally.get.focusRedirectTarget

Related resources

Contributing