Skip to content

Commit 00564d6

Browse files
authored
Add a max height and overflow to select-dropdown (#12038)
Signed-off-by: Jonah Iden <[email protected]>
1 parent d383fe2 commit 00564d6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/core/src/browser/style/select-component.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
outline: var(--theia-focusBorder) solid 1px;
4848
outline-offset: -1px;
4949
user-select: none;
50+
overflow: auto;
5051
}
5152

5253
.theia-select-component-dropdown .theia-select-component-option {

packages/core/src/browser/widgets/select-component.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const SELECT_COMPONENT_CONTAINER = 'select-component-container';
5353
export class SelectComponent extends React.Component<SelectComponentProps, SelectComponentState> {
5454
protected dropdownElement: HTMLElement;
5555
protected fieldRef = React.createRef<HTMLDivElement>();
56+
protected dropdownRef = React.createRef<HTMLDivElement>();
5657
protected mountedListeners: Map<string, EventListenerOrEventListenerObject> = new Map();
5758
protected optimalWidth = 0;
5859
protected optimalHeight = 0;
@@ -124,8 +125,10 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
124125
}
125126

126127
protected attachListeners(): void {
127-
const hide = () => {
128-
this.hide();
128+
const hide = (event: MouseEvent) => {
129+
if (!this.dropdownRef.current?.contains(event.target as Node)) {
130+
this.hide();
131+
}
129132
};
130133
this.mountedListeners.set('scroll', hide);
131134
this.mountedListeners.set('wheel', hide);
@@ -317,8 +320,9 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
317320
bottom: invert ? clientRect.top + clientRect.height - this.state.dimensions.top : 'none',
318321
left: this.state.dimensions.left,
319322
width: Math.min(calculatedWidth, maxWidth),
323+
maxHeight: clientRect.height - (invert ? clientRect.height - this.state.dimensions.bottom : this.state.dimensions.top) - this.state.dimensions.height,
320324
position: 'absolute'
321-
}}>
325+
}} ref={this.dropdownRef}>
322326
{items}
323327
</div>;
324328
}

0 commit comments

Comments
 (0)