File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -172,7 +172,8 @@ export const config = {
172
172
'should adjust for the group padding in ltr' ,
173
173
'should adjust for the group padding in rtl' ,
174
174
'should not adjust if all options are within a group, except the selected one' ,
175
- 'should align the first option to the trigger, if nothing is selected'
175
+ 'should align the first option to the trigger, if nothing is selected' ,
176
+ 'should not adjust if option centering is disabled any option under a group is selected'
176
177
] ,
177
178
'mdc-slide-toggle' : [
178
179
// These tests are verifying implementation details that are not relevant for MDC.
Original file line number Diff line number Diff line change @@ -4225,6 +4225,25 @@ describe('MatSelect', () => {
4225
4225
. toBe ( Math . floor ( triggerTop ) , 'Expected trigger to align with the first option.' ) ;
4226
4226
}
4227
4227
} ) ) ;
4228
+
4229
+ it ( 'should not adjust if option centering is disabled any option under a group is selected' ,
4230
+ fakeAsync ( ( ) => {
4231
+ groupFixture . componentInstance . select . disableOptionCentering = true ;
4232
+ groupFixture . componentInstance . control . setValue ( 'oddish-1' ) ;
4233
+ groupFixture . detectChanges ( ) ;
4234
+
4235
+ trigger . click ( ) ;
4236
+ groupFixture . detectChanges ( ) ;
4237
+ flush ( ) ;
4238
+
4239
+ const selected = document . querySelector ( '.cdk-overlay-pane mat-option.mat-selected' ) ! ;
4240
+ const selectedOptionLeft = selected . getBoundingClientRect ( ) . left ;
4241
+ const triggerLeft = trigger . getBoundingClientRect ( ) . left ;
4242
+
4243
+ // 16px is the default option padding
4244
+ expect ( Math . floor ( selectedOptionLeft ) ) . toEqual ( Math . floor ( triggerLeft - 16 ) ) ;
4245
+ } )
4246
+ ) ;
4228
4247
} ) ;
4229
4248
} ) ;
4230
4249
Original file line number Diff line number Diff line change @@ -1282,6 +1282,8 @@ export class MatSelect extends _MatSelectBase<MatSelectChange> implements OnInit
1282
1282
// Adjust the offset, depending on the option padding.
1283
1283
if ( this . multiple ) {
1284
1284
offsetX = SELECT_MULTIPLE_PANEL_PADDING_X ;
1285
+ } else if ( this . disableOptionCentering ) {
1286
+ offsetX = SELECT_PANEL_PADDING_X ;
1285
1287
} else {
1286
1288
let selected = this . _selectionModel . selected [ 0 ] || this . options . first ;
1287
1289
offsetX = selected && selected . group ? SELECT_PANEL_INDENT_PADDING_X : SELECT_PANEL_PADDING_X ;
You can’t perform that action at this time.
0 commit comments