@@ -46,6 +46,11 @@ import 'package:angular_components/utils/disposer/disposer.dart';
4646/// circumstances as the content will be tabbable and so will be worse for
4747/// accessibility.
4848///
49+ /// __Content Reference:__
50+ ///
51+ /// - `focusOnOpen` -- Mark a Focusable or DOM element with #focusOnOpen in the
52+ /// content to have that item be focused when the expansion panel opens.
53+ ///
4954@Component (
5055 selector: 'material-expansionpanel' ,
5156 directives: [
@@ -98,14 +103,35 @@ class MaterialExpansionPanel
98103 : shouldExpandOnLeft = expandOnLeft != null ,
99104 forceContentWhenClosed = forceContent != null ;
100105
106+ Focusable _focusableItem;
107+
101108 /// Set the auto focus child so that we can focus on it when the panel opens.
102109 ///
103110 /// Unfortunately, this only selects the first [AutoFocusDirective] in the
104111 /// contents of the expansion panel, which means that if there is another
105112 /// [AutoFocusDirective] in an <ng-content> that is not the .content, that
106113 /// will get focused instead of the [AutoFocusDirective] inside the .content.
114+ @Deprecated (
115+ 'Please tag the element or widget to focus on open with #focusOnOpen' )
107116 @ContentChild (AutoFocusDirective )
108- AutoFocusDirective autoFocusChild;
117+ set autoFocusChild (AutoFocusDirective focus) {
118+ _focusableItem = focus;
119+ }
120+
121+ /// Sets the focus child so that we can focus on it when the panel opens.
122+ @ContentChild ('focusOnOpen' )
123+ set focusElement (dynamic element) {
124+ if (element is Focusable ) {
125+ _focusableItem = element;
126+ } else if (element is ElementRef ) {
127+ _focusableItem = RootFocusable (element.nativeElement);
128+ } else {
129+ assert (
130+ element == null ,
131+ 'Warning expansion panel content has a #focus'
132+ 'child which is not an Element, or Focusable' );
133+ }
134+ }
109135
110136 HtmlElement _mainPanel;
111137 @ViewChild ('mainPanel' )
@@ -499,9 +525,9 @@ class MaterialExpansionPanel
499525 _isExpanded.value = expand;
500526 if (byUserAction) _isExpandedChangeByUserAction.add (expand);
501527 _changeDetector.markForCheck ();
502- if (expand && autoFocusChild != null ) {
528+ if (expand && _focusableItem != null ) {
503529 _domService.scheduleWrite (() {
504- autoFocusChild .focus ();
530+ _focusableItem .focus ();
505531 });
506532 }
507533 if (stateWasInitialized) _transitionHeightChange (expand);
0 commit comments