Skip to content

Commit 50a9ffa

Browse files
Elliott Marquezcopybara-github
authored andcommitted
feat(select): add menuAlign to allow end-aligning the select menu
PiperOrigin-RevId: 592384480
1 parent 4bb9418 commit 50a9ffa

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

select/demo/demo.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ const collection = new MaterialCollection<KnobTypesToKnobs<StoryKnobs>>(
3535
new Knob('disabled', {ui: boolInput(), defaultValue: false}),
3636
new Knob('errorText', {ui: textInput(), defaultValue: ''}),
3737
new Knob('supportingText', {ui: textInput(), defaultValue: ''}),
38+
new Knob('menuAlign', {
39+
defaultValue: 'start' as const,
40+
ui: selectDropdown<'start' | 'end'>({
41+
options: [
42+
{label: 'start', value: 'start'},
43+
{label: 'end', value: 'end'},
44+
],
45+
}),
46+
}),
3847
new Knob('menuPositioning', {
3948
defaultValue: 'popover' as const,
4049
ui: selectDropdown<'absolute' | 'fixed' | 'popover'>({

select/demo/stories.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface StoryKnobs {
2424
supportingText: string;
2525
error: boolean;
2626
clampMenuWidth: boolean;
27+
menuAlign: 'start' | 'end' | undefined;
2728
menuPositioning: 'absolute' | 'fixed' | 'popover' | undefined;
2829

2930
'md-select Slots': void;
@@ -35,15 +36,18 @@ const selects: MaterialStoryInit<StoryKnobs> = {
3536
name: 'Selects',
3637
render(knobs) {
3738
return html`
38-
<div style="display: flex; gap: 16px">
39+
<div
40+
style="display: flex; gap: 16px;flex-direction: column;align-items:end;border: 1px solid black;">
3941
<md-filled-select
42+
style="min-width: 100px;width: fit-content;"
4043
.label=${knobs.label}
4144
.quick=${knobs.quick}
4245
.required=${knobs.required}
4346
.disabled=${knobs.disabled}
4447
.errorText=${knobs.errorText}
4548
.supportingText=${knobs.supportingText}
4649
.clampMenuWidth=${knobs.clampMenuWidth}
50+
.menuAlign=${knobs.menuAlign!}
4751
.menuPositioning=${knobs.menuPositioning!}
4852
.typeaheadDelay=${knobs.typeaheadDelay}
4953
.error=${knobs.error}>
@@ -60,6 +64,7 @@ const selects: MaterialStoryInit<StoryKnobs> = {
6064
.errorText=${knobs.errorText}
6165
.supportingText=${knobs.supportingText}
6266
.clampMenuWidth=${knobs.clampMenuWidth}
67+
.menuAlign=${knobs.menuAlign!}
6368
.menuPositioning=${knobs.menuPositioning!}
6469
.typeaheadDelay=${knobs.typeaheadDelay}
6570
.error=${knobs.error}>

select/internal/select.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ export abstract class Select extends selectBaseClass {
153153
*/
154154
@property({attribute: 'display-text'}) displayText = '';
155155

156+
/**
157+
* Whether the menu should be aligned to the start or the end of the select's
158+
* textbox.
159+
*/
160+
@property({attribute: 'menu-align'}) menuAlign: 'start'|'end' = 'start';
161+
156162
/**
157163
* The value of the currently selected option.
158164
*
@@ -478,6 +484,8 @@ export abstract class Select extends selectBaseClass {
478484
.quick=${this.quick}
479485
.positioning=${this.menuPositioning}
480486
.typeaheadDelay=${this.typeaheadDelay}
487+
.anchorCorner=${this.menuAlign === 'start'? 'end-start' : 'end-end'}
488+
.menuCorner=${this.menuAlign === 'start'? 'start-start' : 'start-end'}
481489
@opening=${this.handleOpening}
482490
@opened=${this.redispatchEvent}
483491
@closing=${this.redispatchEvent}

0 commit comments

Comments
 (0)