mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert <Select /> to use <FixedSizeList /> when having lots of options
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f6193718ff
commit
46d1a5c673
@ -178,7 +178,6 @@ export class NamespaceSelectFilter extends React.Component<SelectProps> {
|
|||||||
showAllNamespacesOption={true}
|
showAllNamespacesOption={true}
|
||||||
closeMenuOnSelect={false}
|
closeMenuOnSelect={false}
|
||||||
controlShouldRenderValue={false}
|
controlShouldRenderValue={false}
|
||||||
placeholder={""}
|
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onBlur={this.reset}
|
onBlur={this.reset}
|
||||||
formatOptionLabel={this.formatOptionLabel}
|
formatOptionLabel={this.formatOptionLabel}
|
||||||
|
|||||||
@ -91,7 +91,7 @@ html {
|
|||||||
&__menu {
|
&__menu {
|
||||||
background: var(--select-menu-bgc);
|
background: var(--select-menu-bgc);
|
||||||
box-shadow: inset 0 0 0 1px var(--select-menu-border-color);
|
box-shadow: inset 0 0 0 1px var(--select-menu-border-color);
|
||||||
width: max-content;
|
width: 400px;
|
||||||
min-width: 100%;
|
min-width: 100%;
|
||||||
|
|
||||||
&-list {
|
&-list {
|
||||||
|
|||||||
@ -31,8 +31,9 @@ import Creatable, { CreatableProps } from "react-select/creatable";
|
|||||||
|
|
||||||
import { ThemeStore } from "../../theme.store";
|
import { ThemeStore } from "../../theme.store";
|
||||||
import { boundMethod, cssNames } from "../../utils";
|
import { boundMethod, cssNames } from "../../utils";
|
||||||
|
import { FixedSizeList } from "react-window";
|
||||||
|
|
||||||
const { Menu } = components;
|
const { Menu, MenuList } = components;
|
||||||
|
|
||||||
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
|
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
@ -150,6 +151,29 @@ export class Select extends React.Component<SelectProps> {
|
|||||||
className={cssNames(menuClass, this.themeClass, props.className)}
|
className={cssNames(menuClass, this.themeClass, props.className)}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
MenuList: props => {
|
||||||
|
const height = 35;
|
||||||
|
const { options, children, maxHeight, getValue } = props;
|
||||||
|
const [value] = getValue();
|
||||||
|
const initialOffset = options.indexOf(value) * height;
|
||||||
|
const rChildren = React.Children.toArray(children);
|
||||||
|
|
||||||
|
if (rChildren.length < 200) {
|
||||||
|
return <MenuList {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FixedSizeList
|
||||||
|
height={maxHeight}
|
||||||
|
itemCount={rChildren.length}
|
||||||
|
itemSize={30}
|
||||||
|
initialScrollOffset={initialOffset}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
{({ index, style }) => <div style={style}>{rChildren[index]}</div>}
|
||||||
|
</FixedSizeList>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user