Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit c50eb0c

Browse files
cissyshinshahan
authored andcommitted
Introduce a new attribute input on popup source directive to decide whether to set the popup related aria attributes.
This defaults to true and should be turned off for the popup source in select components where the popup source isn't the click target. PiperOrigin-RevId: 205179702
1 parent 4d582b8 commit c50eb0c

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

lib/src/laminate/popup/dom_popup_source.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ class DomPopupSourceFactory {
2828
/// Returns a new [DomPopupSource] from [sourceElement].
2929
DomPopupSource createPopupSource(HtmlElement sourceElement,
3030
{Alignment alignOriginX = Alignment.Start,
31-
Alignment alignOriginY = Alignment.Start}) {
31+
Alignment alignOriginY = Alignment.Start,
32+
bool initAriaAttributes = true}) {
3233
return new DomPopupSource(_asyncMeasureSize, sourceElement,
33-
alignOriginX: alignOriginX, alignOriginY: alignOriginY);
34+
alignOriginX: alignOriginX,
35+
alignOriginY: alignOriginY,
36+
initAriaAttributes: initAriaAttributes);
3437
}
3538

3639
/// Returns a stream of client sizes for [element], and offsets with the
@@ -54,15 +57,22 @@ class DomPopupSource implements ElementPopupSource {
5457

5558
final AsyncMeasureSize<HtmlElement> _asyncMeasureSize;
5659
final HtmlElement sourceElement;
60+
final bool _initAriaAttributes;
5761

5862
/// Creates a new source from a measure function and source DOM element.
5963
///
6064
/// Setting [alignOriginX] and [alignOriginY] is used for calculating what
6165
/// the x and y position should be.
66+
///
67+
/// [initAriaAttributes] decides whether to set the popup related aria
68+
/// attributes. This defaults to true and can be set to false for cases where
69+
/// the popup source isn't the focus target.
6270
DomPopupSource(this._asyncMeasureSize, this.sourceElement,
6371
{Alignment alignOriginX = Alignment.Start,
6472
Alignment alignOriginY = Alignment.Start,
65-
Point transform = const Point(0, 0)}) {
73+
Point transform = const Point(0, 0),
74+
bool initAriaAttributes = true})
75+
: _initAriaAttributes = initAriaAttributes {
6676
_alignOriginX = alignOriginX;
6777
_alignOriginY = alignOriginY;
6878
}
@@ -89,7 +99,7 @@ class DomPopupSource implements ElementPopupSource {
8999

90100
@override
91101
set popupId(String id) {
92-
if (id == null) return;
102+
if (id == null || !_initAriaAttributes) return;
93103
sourceElement
94104
..setAttribute('aria-owns', id)
95105
..setAttribute('aria-haspopup', 'true');

lib/src/laminate/popup/popup_source_directive.dart

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:angular_components/focus/focus_interface.dart';
1111
import 'package:angular_components/laminate/enums/alignment.dart';
1212
import 'package:angular_components/src/laminate/popup/dom_popup_source.dart';
1313
import 'package:angular_components/src/laminate/popup/popup_source.dart';
14+
import 'package:angular_components/utils/angular/properties/properties.dart';
1415
import 'package:angular_components/utils/angular/reference/reference.dart';
1516

1617
/// A directive that exposes the [PopupSource] interface as `popupSource`.
@@ -23,6 +24,7 @@ import 'package:angular_components/utils/angular/reference/reference.dart';
2324
class PopupSourceDirective
2425
implements ElementPopupSource, AfterViewInit, OnDestroy {
2526
final DomPopupSourceFactory _domPopupSourceFactory;
27+
final bool _initAriaAttributes;
2628
HtmlElement _element;
2729
ReferenceDirective _referenceDirective;
2830
Focusable _focusable;
@@ -33,8 +35,17 @@ class PopupSourceDirective
3335
PopupSource _popupSource;
3436
String _popupId;
3537

36-
PopupSourceDirective(this._domPopupSourceFactory, this._element,
37-
@Optional() this._referenceDirective, @Optional() this._focusable);
38+
/// [initPopupAriaAttributes] is an attribute input that decide whether to
39+
/// set the popup related aria attributes. This defaults to true and can be
40+
/// set to false for cases where the popup source isn't the focus target.
41+
PopupSourceDirective(
42+
this._domPopupSourceFactory,
43+
this._element,
44+
@Optional() this._referenceDirective,
45+
@Optional() this._focusable,
46+
@Attribute('initPopupAriaAttributes') String initAriaAttributes)
47+
: _initAriaAttributes =
48+
attributeToBool(initAriaAttributes, defaultValue: true);
3849

3950
@override
4051
ngOnDestroy() {
@@ -116,11 +127,10 @@ class PopupSourceDirective
116127
}
117128

118129
void _updateSource() {
119-
_popupSource = _domPopupSourceFactory.createPopupSource(
120-
_element,
121-
alignOriginX: _alignOriginX,
122-
alignOriginY: _alignOriginY,
123-
);
130+
_popupSource = _domPopupSourceFactory.createPopupSource(_element,
131+
alignOriginX: _alignOriginX,
132+
alignOriginY: _alignOriginY,
133+
initAriaAttributes: _initAriaAttributes);
124134

125135
if (_popupId != null) {
126136
_popupSource.popupId = _popupId;

lib/src/material_tooltip/tooltip_source.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class MaterialTooltipSourceDirective extends PopupSourceDirective
5555
domPopupSourceFactory,
5656
element,
5757
/* referenceDirective */ null,
58-
/* focusable */ null) {
58+
/* focusable */ null,
59+
/* initAriaAttributes */ null) {
5960
_show = new DelayedAction(tooltipShowDelay, activate);
6061
}
6162

lib/src/material_tooltip/tooltip_target.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ abstract class TooltipTarget extends PopupSourceDirective {
193193
domPopupSourceFactory,
194194
_element,
195195
/* referenceDirective */ null,
196-
/* focusable */ null);
196+
/* focusable */ null,
197+
/* initAriaAttributes */ null);
197198

198199
/// Sets the tooltip associated with this target.
199200
void setTooltip(Tooltip component) {

0 commit comments

Comments
 (0)