This repository was archived by the owner on May 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,15 @@ import 'package:angular_components/utils/browser/events/events.dart';
3131 directives: const [NgIf ],
3232 changeDetection: ChangeDetectionStrategy .OnPush ,
3333 visibility: Visibility .local)
34- class MaterialToggleComponent {
34+ class MaterialToggleComponent implements AfterViewInit {
35+ @ViewChild ('toggle' )
36+ HtmlElement toggleElement;
37+
38+ @override
39+ void ngAfterViewInit () {
40+ _syncAriaPressed ();
41+ }
42+
3543 /// Enables/disables the toggle button.
3644 ///
3745 /// `true` is disabled and `false` is enabled.
@@ -42,7 +50,13 @@ class MaterialToggleComponent {
4250 ///
4351 /// `true` is ON and `false` is OFF.
4452 @Input ()
45- bool checked = false ;
53+ set checked (bool value) {
54+ _checked = value;
55+ _syncAriaPressed ();
56+ }
57+
58+ bool get checked => _checked;
59+ bool _checked = false ;
4660
4761 final _controller = new StreamController <bool >.broadcast ();
4862
@@ -108,4 +122,9 @@ class MaterialToggleComponent {
108122 keyEvent.stopPropagation ();
109123 }
110124 }
125+
126+ void _syncAriaPressed () {
127+ if (toggleElement == null ) return ;
128+ toggleElement.attributes['aria-pressed' ] = '$checked ' ;
129+ }
111130}
Original file line number Diff line number Diff line change 33 for details. All rights reserved. Use of this source code is governed by a
44 BSD-style license that can be found in the LICENSE file.
55-->
6- < div attr.aria-pressed =" {{checked}} "
6+ < div #toggle
77 attr.aria-disabled ="{{disabled}} "
88 attr.aria-label ="{{ariaLabel}} "
99 class ="material-toggle "
You can’t perform that action at this time.
0 commit comments