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

Commit b8cbd19

Browse files
authored
Update all components (#137)
* Dynamic Component: Add ability to use `ComponentFactory` instead of a `Type`. * Material Dialog: Fix header mixin. * Material Checkbox: Add ability to make readonly. * Material Input: Make local required errors to make controls invalid even when the control has not been interacted with. * Material Popup: * Add an option to reposition visible popups every frame with `trackLayoutChanges`. * Merge laminate/components/popup into Material Popup. * Material Select: Allow dropdown to display an error while it's closed. * Material Tree: * Added shift selection/deselection. * Fix glyphs always shown expanded when `expandAll = true`. * Material Yes/No Buttons: Add dense style. * Scorecard: Update tab index to prevent scroll errors when going through buttons with tabs. * Add new color utils. * Migrate uses of `GlyphComponent` to `MaterialIconComponent`. * Migrate uses of `ElementRef` to `Element`. * Remove duplicate PopupSourceDirective. * Remove deprecated popup `matchSourceWidth` options. * Updates to use metadata inheritance. * Remove unused library statements. * Update documentation.
1 parent eb956f1 commit b8cbd19

File tree

178 files changed

+1232
-1718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+1232
-1718
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
## 0.6.0-alpha+2
2+
3+
> NOTE: This code is considered production quality, but depends on angular:
4+
> 4.0.0-alpha+2. The alpha tag represents the evolving nature of the AngularDart
5+
> api, not code quality (4.0.0-alpha is used in production Google apps).
6+
7+
* Dynamic Component: Add ability to use `ComponentFactory` instead of a `Type`.
8+
* Material Dialog: Fix header mixin.
9+
* Material Checkbox: Add ability to make readonly.
10+
* Material Input: Make local required errors to make controls invalid even when
11+
the control has not been interacted with.
12+
* Material Popup:
13+
* Add an option to reposition visible popups every frame with
14+
`trackLayoutChanges`.
15+
* Merge laminate/components/popup into Material Popup.
16+
* Material Select: Allow dropdown to display an error while it's closed.
17+
* Material Tree:
18+
* Added shift selection/deselection.
19+
* Fix glyphs always shown expanded when `expandAll = true`.
20+
* Material Yes/No Buttons: Add dense style.
21+
* Scorecard: Update tab index to prevent scroll errors when going through
22+
buttons with tabs.
23+
* Add new color utils.
24+
* Migrate uses of `GlyphComponent` to `MaterialIconComponent`.
25+
* Migrate uses of `ElementRef` to `Element`.
26+
* Remove duplicate PopupSourceDirective.
27+
* Remove deprecated popup `matchSourceWidth` options.
28+
* Updates to use metadata inheritance.
29+
* Remove unused library statements.
30+
* Update documentation.
31+
132
## 0.6.0-alpha+1
233

334
> NOTE: This code is considered production quality, but depends on angular:

lib/src/components/auto_dismiss/auto_dismiss.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:html';
67

78
import 'package:angular/angular.dart';
89

@@ -31,7 +32,7 @@ class AutoDismissDirective {
3132
final Stream _click;
3233
final NgZone _zone;
3334

34-
AutoDismissDirective(ElementRef element, this._zone)
35+
AutoDismissDirective(HtmlElement element, this._zone)
3536
: _click = triggersOutside(element);
3637

3738
bool _ignoreClicks = false;

lib/src/components/button_decorator/button_decorator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ButtonDirective extends RootFocusable with HasTabIndex {
4141

4242
String _hostTabIndex;
4343

44-
ButtonDirective(ElementRef element) : super(element);
44+
ButtonDirective(Element element) : super(element);
4545

4646
/// String value to be passed to aria-disabled.
4747
String get disabledStr => '$_disabled';

lib/src/components/button_decorator/button_decorator.scss.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
[buttonDecorator]{cursor:pointer}[buttonDecorator].is-disabled{cursor:not-allowed}
7+

lib/src/components/dynamic_component/dynamic_component.dart

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ import '../../utils/async/async.dart';
1717
///
1818
/// ... *ngFor="item in items">
1919
/// <dynamic-component
20-
/// [componentType]="aTypeThatMayNotRenderValue"
20+
/// [componentFactory]="aFactoryThatMayNotRenderValue"
2121
/// [value]="item">
2222
/// </dynamic-component>
2323
///
2424
@Component(
2525
selector: 'dynamic-component',
26-
// #marker variable is used to refer to the <div> tag later when calling
27-
// DynamicComponentLoader.loadNextToLocation. The tag does not have to be
28-
// <span>. It can be anything. In this case, we simply needed something
29-
// that's not visible, and <span> does the job perfectly.
30-
template: '''<span #marker></span>''')
26+
template: '''<template #marker></template>''')
3127
class DynamicComponent implements OnDestroy {
32-
final DynamicComponentLoader _componentLoader;
28+
final SlowComponentLoader _slowComponentLoader;
29+
final ComponentLoader _componentLoader;
3330
final ChangeDetectorRef _changeDetectorRef;
3431
final _onLoadController = new LazyStreamController<ComponentRef>();
3532

@@ -47,14 +44,16 @@ class DynamicComponent implements OnDestroy {
4744

4845
ComponentRef _childComponent;
4946
Type _componentType;
47+
ComponentFactory _componentFactory;
5048
Object _value;
5149

5250
/// Fired when component is loaded allowing clients to get a handle on the
5351
/// component loaded.
5452
@Output()
5553
Stream<ComponentRef> get onLoad => _onLoadController.stream;
5654

57-
DynamicComponent(this._componentLoader, this._changeDetectorRef);
55+
DynamicComponent(this._slowComponentLoader, this._changeDetectorRef,
56+
this._componentLoader);
5857

5958
/// Returns the loaded dynamic component reference.
6059
ComponentRef get childComponent => _childComponent;
@@ -71,6 +70,7 @@ class DynamicComponent implements OnDestroy {
7170
}
7271

7372
/// The type of component to dynamically render.
73+
@Deprecated('Use componentFactory instead as it is more tree-shakable')
7474
@Input()
7575
set componentType(Type dartType) {
7676
_disposeChildComponent();
@@ -85,24 +85,51 @@ class DynamicComponent implements OnDestroy {
8585
}
8686
}
8787

88+
/// The type of component to dynamically render.
89+
@Input()
90+
set componentFactory(ComponentFactory component) {
91+
_disposeChildComponent();
92+
_componentFactory = component;
93+
if (component == null) {
94+
return;
95+
}
96+
if (_viewContainerRef != null) {
97+
_initialize();
98+
} else {
99+
_loadDeferred = true;
100+
}
101+
}
102+
88103
void _initialize() {
89-
Type loadType = _componentType;
90-
_componentLoader
91-
.loadNextToLocation(loadType, _viewContainerRef)
92-
.then((ComponentRef componentRef) {
93-
if (loadType != _componentType) {
94-
// During the load time, the component type has changed,
95-
// and the type we just loaded is no longer valid.
96-
componentRef.destroy();
97-
return;
98-
}
104+
if (_componentFactory != null) {
99105
if (_childComponent != null) {
100106
throw 'Attempting to overwrite a dynamic component';
101107
}
102-
_childComponent = componentRef;
103-
_onLoadController.add(componentRef);
108+
109+
_childComponent = _componentLoader.loadNextToLocation(
110+
_componentFactory, _viewContainerRef);
111+
_onLoadController.add(_childComponent);
104112
_updateChildComponent();
105-
});
113+
} else {
114+
// TODO(google): Remove this code once componentType is no longer used.
115+
Type loadType = _componentType;
116+
_slowComponentLoader
117+
.loadNextToLocation(loadType, _viewContainerRef)
118+
.then((ComponentRef componentRef) {
119+
if (loadType != _componentType) {
120+
// During the load time, the component type has changed,
121+
// and the type we just loaded is no longer valid.
122+
componentRef.destroy();
123+
return;
124+
}
125+
if (_childComponent != null) {
126+
throw 'Attempting to overwrite a dynamic component';
127+
}
128+
_childComponent = componentRef;
129+
_onLoadController.add(componentRef);
130+
_updateChildComponent();
131+
});
132+
}
106133
}
107134

108135
/// The value to set on the component if the component implements

lib/src/components/focus/focus.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:html' show KeyCode, KeyboardEvent, Element;
6+
import 'dart:html' show KeyCode, KeyboardEvent, Element, HtmlElement;
77

88
import 'package:angular/angular.dart';
99

@@ -24,22 +24,21 @@ abstract class Focusable {
2424
/// An abstract class for components to extend if their programmatic focus
2525
/// should simply put focus on root element.
2626
abstract class RootFocusable implements Focusable, Disposable {
27-
ElementRef _root;
27+
Element _root;
2828
RootFocusable(this._root);
2929

3030
@override
3131
void focus() {
3232
if (_root == null) return;
33-
Element element = _root.nativeElement;
3433
// if element does not have positive tab index attribute already specified
3534
// or is native element.
3635
// NOTE: even for elements with tab index unspecified it will return
3736
// tabIndex as "-1" and we have to set it to "-1"
3837
// to actually make it focusable.
39-
if (element.tabIndex < 0) {
40-
element.tabIndex = -1;
38+
if (_root.tabIndex < 0) {
39+
_root.tabIndex = -1;
4140
}
42-
element.focus();
41+
_root.focus();
4342
}
4443

4544
@override
@@ -59,19 +58,19 @@ abstract class ProjectedFocus implements Focusable {
5958
return;
6059
}
6160
focusDelegate.then((delegate) {
62-
assert(delegate is Focusable || delegate is ElementRef);
61+
assert(delegate is Focusable || delegate is Element);
6362
if (delegate is Focusable) {
6463
_resolvedFocusable = delegate;
6564
} else {
66-
_resolvedFocusable = new _FocusableElement(delegate as ElementRef);
65+
_resolvedFocusable = new _FocusableElement(delegate);
6766
}
6867
_resolvedFocusable.focus();
6968
});
7069
}
7170
}
7271

7372
class _FocusableElement extends RootFocusable {
74-
_FocusableElement(ElementRef element) : super(element);
73+
_FocusableElement(HtmlElement element) : super(element);
7574
}
7675

7776
/// A focusable component that can publish to the
@@ -140,7 +139,7 @@ class AutoFocusDirective extends RootFocusable implements OnInit, OnDestroy {
140139
PopupRef _popupRef;
141140

142141
AutoFocusDirective(
143-
ElementRef node,
142+
HtmlElement node,
144143
this._domService,
145144
@Optional() this._focusable,
146145
@Optional() this._modal,
@@ -203,5 +202,5 @@ class AutoFocusDirective extends RootFocusable implements OnInit, OnDestroy {
203202
/// This directive is used to [ViewChild] focusable element in your view.
204203
@Directive(selector: '[focusableElement]', exportAs: 'focusableElement')
205204
class FocusableDirective extends RootFocusable {
206-
FocusableDirective(ElementRef node) : super(node);
205+
FocusableDirective(HtmlElement node) : super(node);
207206
}

lib/src/components/focus/focus_activable_item.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:html';
6+
57
import 'package:angular/angular.dart';
68

79
import './focus.dart';
@@ -20,7 +22,7 @@ class FocusActivableItemDirective extends RootFocusable
2022
@override
2123
String key;
2224

23-
FocusActivableItemDirective(ElementRef root) : super(root);
25+
FocusActivableItemDirective(HtmlElement root) : super(root);
2426
}
2527

2628
/// A focusable component with a matching [key].

lib/src/components/focus/focus_item.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:html' show KeyboardEvent;
6+
import 'dart:html' show KeyboardEvent, HtmlElement;
77

88
import 'package:angular/angular.dart';
99

@@ -32,7 +32,7 @@ import './focus.dart';
3232
class FocusItemDirective extends RootFocusable implements FocusableItem {
3333
final String role;
3434

35-
FocusItemDirective(ElementRef element, @Attribute('role') String role)
35+
FocusItemDirective(HtmlElement element, @Attribute('role') String role)
3636
: this.role = role ?? 'listitem',
3737
super(element);
3838

lib/src/components/focus/focus_trap.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ class FocusTrapComponent implements OnDestroy {
8585
@Directive(selector: '[focusContentWrapper]')
8686
class FocusContentWrapper extends FocusableDirective {
8787
Element _element;
88-
FocusContentWrapper(ElementRef elementRef)
89-
: _element = elementRef.nativeElement,
90-
super(elementRef);
88+
FocusContentWrapper(HtmlElement element)
89+
: _element = element,
90+
super(element);
9191

9292
Element get element => _element;
9393
}

lib/src/components/focus/focus_trap.scss.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
* BSD-style license that can be found in the LICENSE file.
55
*/
66
:host{display:block}[focusContentWrapper]{height:inherit;max-height:inherit}
7+

0 commit comments

Comments
 (0)