Skip to content

Commit

Permalink
Add a max height and overflow to select-dropdown (#12038)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonah Iden <[email protected]>
  • Loading branch information
jonah-iden authored Jan 18, 2023
1 parent d383fe2 commit 00564d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/core/src/browser/style/select-component.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
outline: var(--theia-focusBorder) solid 1px;
outline-offset: -1px;
user-select: none;
overflow: auto;
}

.theia-select-component-dropdown .theia-select-component-option {
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/browser/widgets/select-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const SELECT_COMPONENT_CONTAINER = 'select-component-container';
export class SelectComponent extends React.Component<SelectComponentProps, SelectComponentState> {
protected dropdownElement: HTMLElement;
protected fieldRef = React.createRef<HTMLDivElement>();
protected dropdownRef = React.createRef<HTMLDivElement>();
protected mountedListeners: Map<string, EventListenerOrEventListenerObject> = new Map();
protected optimalWidth = 0;
protected optimalHeight = 0;
Expand Down Expand Up @@ -124,8 +125,10 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
}

protected attachListeners(): void {
const hide = () => {
this.hide();
const hide = (event: MouseEvent) => {
if (!this.dropdownRef.current?.contains(event.target as Node)) {
this.hide();
}
};
this.mountedListeners.set('scroll', hide);
this.mountedListeners.set('wheel', hide);
Expand Down Expand Up @@ -317,8 +320,9 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
bottom: invert ? clientRect.top + clientRect.height - this.state.dimensions.top : 'none',
left: this.state.dimensions.left,
width: Math.min(calculatedWidth, maxWidth),
maxHeight: clientRect.height - (invert ? clientRect.height - this.state.dimensions.bottom : this.state.dimensions.top) - this.state.dimensions.height,
position: 'absolute'
}}>
}} ref={this.dropdownRef}>
{items}
</div>;
}
Expand Down

0 comments on commit 00564d6

Please sign in to comment.