• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5part of engine;
6
7/// Manages semantics configurations that represent live regions.
8///
9/// "aria-live" attribute is added to communicate the live region to the
10/// assistive technology.
11///
12/// The usage of "aria-live" is browser-dependent.
13///
14/// VoiceOver only supports "aria-live" with "polite" politeness setting. When
15/// the inner html content is changed. It doesn't read the "aria-label".
16///
17/// When there is an aria-live attribute added, assistive technologies read the
18/// label of the element. See [LabelAndValue]. If there is no label provided
19/// no content will be read, therefore DOM is cleaned.
20class LiveRegion extends RoleManager {
21  LiveRegion(SemanticsObject semanticsObject)
22      : super(Role.labelAndValue, semanticsObject);
23
24  @override
25  void update() {
26    if (semanticsObject.hasLabel) {
27      semanticsObject.element.setAttribute('aria-live', 'polite');
28    } else {
29      _cleanupDom();
30    }
31  }
32
33  void _cleanupDom() {
34    semanticsObject.element.attributes.remove('aria-live');
35  }
36
37  @override
38  void dispose() {
39    _cleanupDom();
40  }
41}
42