mat-select: panel is partially off screen making some options unselectable (mobile)
Reproduction
Steps to reproduce:
- Create a mat-select with a dozen or so options
- View page on mobile device in landscape
- Open mat-select
- Try to select the last option without first selecting another option.
A StackBlitz with the issue can be found here (source). If you view it the page on an iPhone X or other similarly sized phone in landscape, the 12th option is not selectable without first selecting a different option.
Expected Behavior
If there is not enough space for the panel, it should either move up or shrink so that all options are able to be scrolled onto the screen
Actual Behavior
In some cases, on short screens such as smaller phones in landscape, the panel for mat-select can shift such that either the top or the bottom of the panel is off screen. This prevents users from selecting the first or last option of the list.
Environment
- Angular: 8.2.7
- CDK/Material: 8.2
- Browser(s): Chrome 78/Safari on iOS 12
- Operating System (e.g. Windows, macOS, Ubuntu): iOS12 , Windows 10, Android 10
I am seeing the same issue. We have struggled to find a CSS workaround. Does anyone have a suggestion?
(revisiting older issues as part of a triaging fix-it)
I can confirm that this happens when the screen height is very small (on a desktop browser), though not for any real-life devices. It's caused by the select's unique positioning that puts the selected item in the overlay over the matching text in the trigger, which is overriding the overlay's normal mechanism for keeping the panel on-screen. This should get fixed when we build an MDC-web version of the select, which won't have this same overlay positioning behavior.
On my 2560x1440 screen device, it still happen when I have a mat-select within a MatDialog
What worked for me was limiting the height of div that enclosed the options.
Try putting the following in styles.scss (it won't work in the component .scss file)
div[role="listbox"]{
max-height: 65vh !important;
}
Fixed in the MDC based components (now the default)
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.