Skip to content

Commit 1ba4461

Browse files
committed
Improve dropdown menu positioning and width alignment relative to the anchor element
- add translations to [Fragment]
1 parent 4c7a692 commit 1ba4461

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎packages/ui/src/components/editor/common/Dropdown/Dropdown.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ export const Dropdown = <T extends string>(props: Dropdown.Props<T>) => {
8989
])}
9090
/>
9191
</button>
92-
{is_open && <DropdownMenu items={menu_items} />}
92+
{is_open && (
93+
<DropdownMenu
94+
items={menu_items}
95+
anchor_ref={dropdown_ref}
96+
is_open={is_open}
97+
/>
98+
)}
9399
</div>
94100
)
95101
}

‎packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.module.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
z-index: 2;
77
width: max-content;
88
text-align: left;
9-
min-width: max(100%, 110px);
9+
min-width: 100%;
1010

1111
&__inner {
1212
background-color: var(--vscode-quickInput-background);

‎packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
3838
const dropdown_rect = dropdown_ref.current.getBoundingClientRect()
3939

4040
let top = anchor_rect.bottom
41+
const actual_dropdown_width = Math.max(
42+
dropdown_rect.width,
43+
anchor_rect.width
44+
)
45+
4146
let left = props.match_anchor_width
4247
? anchor_rect.left
43-
: anchor_rect.right - dropdown_rect.width
48+
: anchor_rect.right - actual_dropdown_width
4449
let width: string | undefined
4550

4651
if (props.match_anchor_width) {
4752
width = `${anchor_rect.width}px`
4853
} else if (left < 0) {
4954
left = 4
50-
} else if (left + dropdown_rect.width > window.innerWidth) {
51-
left = window.innerWidth - dropdown_rect.width - 4
55+
} else if (left + actual_dropdown_width > window.innerWidth) {
56+
left = window.innerWidth - actual_dropdown_width - 4
5257
}
5358

5459
const viewport_height = window.innerHeight
@@ -60,7 +65,8 @@ export const DropdownMenu: React.FC<DropdownMenu.Props> = (props) => {
6065
set_anchor_style({
6166
top: `${top}px`,
6267
left: `${left}px`,
63-
width
68+
width,
69+
minWidth: `${anchor_rect.width}px`
6470
})
6571
} else if (!props.is_open) {
6672
set_anchor_style({})

0 commit comments

Comments
 (0)