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

Commit b336202

Browse files
samiermerchantnshahan
authored andcommitted
Add specific class names, acx-showhide-hide and acx-showhide-hidden, for the hide and hidden css classes of the showhide directive.
PiperOrigin-RevId: 199221866
1 parent 3c8271b commit b336202

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/utils/showhide/showhide.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ import 'package:angular_components/utils/browser/dom_service/angular_2.dart';
1111

1212
/// Shows or hides the given HTML element based on an expression.
1313
///
14-
/// The element is shown or hidden by removing or adding the 'ng-hide' css
15-
/// class at first, and 'ng-hidden' at the end of transition (or after 16ms
16-
/// delay if no transition happened).
14+
/// The element is shown or hidden by removing or adding the
15+
/// 'acx-showhide-hide' css class at first, and 'acx-showhide-hidden' at the end
16+
/// of transition (or after 16ms delay if no transition happened).
1717
@Directive(
1818
selector: '[showhide]',
1919
)
2020
class ShowHideDirective implements OnInit, OnDestroy {
21-
static String _hideClass = 'ng-hide';
22-
static String _hiddenClass = 'ng-hidden';
23-
// time after transition started, when ng-hidden is added forcefully
21+
static const _hideClassLegacy = 'ng-hide';
22+
static const _hideClass = 'acx-showhide-hide';
23+
24+
static const _hiddenClassLegacy = 'ng-hidden';
25+
static const _hiddenClass = 'acx-showhide-hidden';
26+
// time after transition started, when acx-showhide-hidden is added forcefully
2427
static int _transitionTimeoutMs = 16;
2528

2629
final Element _element;
@@ -72,7 +75,9 @@ class ShowHideDirective implements OnInit, OnDestroy {
7275
} else {
7376
_initialWritePending = true;
7477
_domService.scheduleWrite(() {
78+
_element.classes.toggle(_hideClassLegacy, !value);
7579
_element.classes.toggle(_hideClass, !value);
80+
_element.classes.toggle(_hiddenClassLegacy, !value);
7681
_element.classes.toggle(_hiddenClass, !value);
7782
_initialWritePending = false;
7883
});
@@ -82,13 +87,16 @@ class ShowHideDirective implements OnInit, OnDestroy {
8287
void _show() {
8388
_stopHiding();
8489
_domService.scheduleRead(() {
85-
if (_initialWritePending || _element.classes.contains(_hiddenClass)) {
90+
if (_initialWritePending ||
91+
_element.classes.contains(_hiddenClassLegacy) ||
92+
_element.classes.contains(_hiddenClass)) {
8693
_domService.scheduleWrite(() {
94+
_element.classes.remove(_hiddenClassLegacy);
8795
_element.classes.remove(_hiddenClass);
8896
});
8997
// remove the ng-hide class in the next event loop, so that effects of
90-
// removing ng-hidden can settle (like changing display from none to
91-
// block)
98+
// removing acx-showhide-hidden can settle (like changing display from
99+
// none to block)
92100
_domService.nextFrame.then((_) {
93101
_removeNgHide();
94102
});
@@ -101,6 +109,7 @@ class ShowHideDirective implements OnInit, OnDestroy {
101109
void _removeNgHide() {
102110
if (_hiding) return;
103111
_domService.scheduleWrite(() {
112+
_element.classes.remove(_hideClassLegacy);
104113
_element.classes.remove(_hideClass);
105114
_onShow.add(_element);
106115
});
@@ -134,6 +143,7 @@ class ShowHideDirective implements OnInit, OnDestroy {
134143
void _hide() {
135144
_hiding = true;
136145
_domService.scheduleWrite(() {
146+
_element.classes.add(_hideClassLegacy);
137147
_element.classes.add(_hideClass);
138148
_onHide.add(_element);
139149
});
@@ -145,6 +155,7 @@ class ShowHideDirective implements OnInit, OnDestroy {
145155
void _hideIfHiding() {
146156
if (_hiding) {
147157
_domService.scheduleWrite(() {
158+
_element.classes.add(_hiddenClassLegacy);
148159
_element.classes.add(_hiddenClass);
149160
});
150161
_onHideEnd.add(_element);

0 commit comments

Comments
 (0)