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
help(MatSelect): MatSelect .cdk-overlay-pane fixed width with Angular Material 15 #26336
Comments
I have same problem and this is my css override solution
It's work like previous version of matSelect except when the matSelect width is longer than an options, the panel width wouldn't expand to the matSelect width. |
@tarn2206 good solution but the |
One provisional solution can give value to the property "_overlayPanelClass" and then use
You can make using a ViewChild
Or even, you create a directive
And use like
See stackblitz |
Thank you for the directive, however, there is a case when the input becomes wider then values, so the dropdown's width becomes smaller than host element. Can we achieve min-width = mat-select width? edit* I've achieved this using this, but since minWith is being applied right after "open", it looks not smooth @Directive({
selector: 'mat-select [autoWidth]'
})
export class MatSelectAutoWidthDirective {
constructor(private matselect: MatSelect,
@Optional()private matFormField:MatFormField) {
this.matselect._overlayPanelClass = 'width-auto'
this.matselect.openedChange
.subscribe(()=>{
if(matselect.panel && this.matFormField) {
this.matselect.panel.nativeElement.style.minWidth = this.matFormField._elementRef.nativeElement.offsetWidth + 'px';
}
})
}
}
` |
@EliseoPlunker @SonicReal Angular team gave us a way to override this 1 - Create CSS Class:
2 - Put this on top of your component:
I believe, for now, this is the best solution. To be honest, I would have preferred |
A slight improvment on @GabrielBB's approach would be to use The advantage is if you have no long options in your list your options will still extend to the minimum of the trigger label. It is particularly helpful in cases where options are dynamically being generated. It also allows for the removal of the
|
Duplicate of #26000. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
What are you trying to do?
I am trying to migrate a large app using Angular Material to v15 and like many of us I have to overwrite some default styles on Angular Material components.
I am facing an issue with the new MatSelect v15. It seems that now the default behavior is to make the overlay-pane use the exact same width as its
mat-select
related component, directly by setting the width to the element (.cdk-overlay-pane) styles.If the
mat-form-field
ormat-select
have a small width, themat-option
texts get word wrapped and it is pretty ugly :https://stackblitz.com/edit/angular-sbq67h?file=src/app/select-overview-example.html
Is there any way I could prevent this fixed width on the related
.cdk-overlay-pane
for mymat-select
component ?What troubleshooting steps have you tried?
Adding
white-space: nowrap;
to.mat-mdc-option .mdc-list-item__primary-text
prevent the wrapping issue but the.cdk-overlay-pane
fixed width do not allow any overflow. The @inputpanelClass
can't help because.cdk-overlay-pane
is a parent.Reproduction
Steps to reproduce:
Environment
The text was updated successfully, but these errors were encountered: