Skip to content

Commit 56367e8

Browse files
author
emoralesb05
committed
feat(select): update the trigger width and overlay state when select is opened
1 parent 93fe0fd commit 56367e8

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

src/cdk/overlay/overlay-directives.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ export class ConnectedOverlayDirective implements OnDestroy, OnChanges {
340340
private _attachOverlay() {
341341
if (!this._overlayRef) {
342342
this._createOverlay();
343+
} else {
344+
// Update the overlay size, in case the directive's inputs have changed
345+
const overlayState = new OverlayState();
346+
this._configureSize(overlayState);
347+
this._overlayRef.updateSize(overlayState);
343348
}
344349

345350
this._position.withDirection(this.dir);

src/cdk/overlay/overlay-ref.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class OverlayRef implements PortalHost {
4747

4848
// Update the pane element with the given state configuration.
4949
this._updateStackingOrder();
50-
this.updateSize();
50+
this._setSizeStyles();
5151
this.updateDirection();
5252
this.updatePosition();
5353
this._state.scrollStrategy.enable();
@@ -155,8 +155,29 @@ export class OverlayRef implements PortalHost {
155155
this._pane.setAttribute('dir', this._state.direction!);
156156
}
157157

158+
/** Updates the state size of the overlay */
159+
updateSize(state: OverlayState) {
160+
if (state.width || state.width === 0) {
161+
this._state.width = state.width;
162+
}
163+
164+
if (state.height || state.height === 0) {
165+
this._state.height = state.height;
166+
}
167+
168+
if (state.minWidth || state.minWidth === 0) {
169+
this._state.minWidth = state.minWidth;
170+
}
171+
172+
if (state.minHeight || state.minHeight === 0) {
173+
this._state.minHeight = state.minHeight;
174+
}
175+
176+
this._setSizeStyles();
177+
}
178+
158179
/** Updates the size of the overlay based on the overlay config. */
159-
updateSize() {
180+
private _setSizeStyles() {
160181
if (this._state.width || this._state.width === 0) {
161182
this._pane.style.width = formatCssUnit(this._state.width);
162183
}

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
176176
if (!this._overlayRef) {
177177
this._createOverlay();
178178
} else {
179-
/** Update the panel width, in case the host width has changed */
180-
this._overlayRef.getState().width = this._getHostWidth();
181-
this._overlayRef.updateSize();
179+
// Update the panel width, in case the host width has changed
180+
const overlayState = new OverlayState();
181+
overlayState.width = this._getHostWidth();
182+
this._overlayRef.updateSize(overlayState);
182183
}
183184

184185
if (this._overlayRef && !this._overlayRef.hasAttached()) {

src/lib/select/select.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
466466
return;
467467
}
468468

469-
/**
470-
* Always set the trigger width since we need to
471-
* update the panel with its new minWidth when opening it
472-
*/
469+
// Always set the trigger width since we need to
470+
// update the panel with its new minWidth when opening it
473471
this._setTriggerWidth();
474472

475473
this._calculateOverlayPosition();

0 commit comments

Comments
 (0)