Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(autocomplete): use overlay api to set conditional panel class #12822

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,20 +618,25 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
.withFlexibleDimensions(false)
.withPush(false)
.withPositions([
{originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top'},
{originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom'}
{
originX: 'start',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top'
},
{
originX: 'start',
originY: 'top',
overlayX: 'start',
overlayY: 'bottom',

// The overlay edge connected to the trigger should have squared corners, while
// the opposite end has rounded corners. We apply a CSS class to swap the
// border-radius based on the overlay position.
panelClass: 'mat-autocomplete-panel-above'
}
]);

// The overlay edge connected to the trigger should have squared corners, while
// the opposite end has rounded corners. We apply a CSS class to swap the
// border-radius based on the overlay position.
this._positionStrategy.positionChanges.subscribe(({connectionPair}) => {
if (this.autocomplete) {
this.autocomplete._classList['mat-autocomplete-panel-above'] =
connectionPair.originY === 'top';
}
});

return this._positionStrategy;
}

Expand Down
11 changes: 6 additions & 5 deletions src/lib/autocomplete/autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ $mat-autocomplete-panel-border-radius: 4px !default;
visibility: hidden;
}

.mat-autocomplete-panel-above & {
border-radius: 0;
border-top-left-radius: $mat-autocomplete-panel-border-radius;
border-top-right-radius: $mat-autocomplete-panel-border-radius;
}

@include cdk-high-contrast {
outline: solid 1px;
}
}

.mat-autocomplete-panel-above {
border-radius: 0;
border-top-left-radius: $mat-autocomplete-panel-border-radius;
border-top-right-radius: $mat-autocomplete-panel-border-radius;
}
3 changes: 1 addition & 2 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,7 @@ describe('MatAutocomplete', () => {
expect(Math.floor(inputTop))
.toEqual(Math.floor(panelBottom), `Expected panel to fall back to above position.`);

expect(panel.querySelector('.mat-autocomplete-panel')!.classList)
.toContain('mat-autocomplete-panel-above');
expect(panel.classList).toContain('mat-autocomplete-panel-above');
}));

it('should allow the panel to expand when the number of results increases', fakeAsync(() => {
Expand Down