Skip to content

Commit

Permalink
Toggle [aria-busy] instead of [busy]
Browse files Browse the repository at this point in the history
Since `<turbo-frame>` elements are custom elements, the framework has
total control over the names of the attributes.

There are existing semantics for what we've introduced as `[busy]`: the
ARIA guidelines suggest toggling [aria-busy="true"][aria-busy] when an
element is loading more content, and `aria-busy="false"` when the
content is loaded.

This provides an "interface" for loading styles through CSS attribute
selectors, and hints to assistive technologies the state of the frame.

As an alternative, we could continue to toggle the `[busy]` attribute,
and encourage consumer applications to monitor mutations to the `[busy]`
attribute (or listen to [`turbo:frame-visit` and `turbo:frame-load`
events][events]) to toggle it themselves.

[aria-busy]: https://www.w3.org/TR/wai-aria-1.1/#aria-busy
[events]: #59
  • Loading branch information
seanpdoyle committed Feb 4, 2021
1 parent f9ca9f8 commit 31b17b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/frames/frame_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
}

requestStarted(request: FetchRequest) {
this.element.setAttribute("busy", "")
this.element.setAttribute("aria-busy", "true")
}

requestPreventedHandlingResponse(request: FetchRequest, response: FetchResponse) {
Expand All @@ -152,7 +152,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest
}

requestFinished(request: FetchRequest) {
this.element.removeAttribute("busy")
this.element.removeAttribute("aria-busy")
}

// Form submission delegate
Expand Down
6 changes: 3 additions & 3 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export class FrameTests extends FunctionalTestCase {
}

async "test following a link driving a frame toggles the [busy] attribute"() {
await this.observeAttributeChanges("frame", "busy")
await this.observeAttributeChanges("frame", "aria-busy")
await this.clickSelector("#hello a")
await this.nextBeat

this.assert.ok(await this.hasSelector("turbo-frame[id=frame][data-was-busy=true]"))
this.assert.notOk(await this.hasSelector("turbo-frame[id=frame][busy]"))
this.assert.ok(await this.hasSelector("turbo-frame[id=frame][data-was-aria-busy=true]"))
this.assert.notOk(await this.hasSelector("turbo-frame[id=frame][aria-busy]"))
}

async "test following a link to a page without a matching frame results in an empty frame"() {
Expand Down

0 comments on commit 31b17b0

Please sign in to comment.