MCPcopy
hub / github.com/palantir/blueprint / Select

Class Select

packages/select/src/components/select/select.tsx:78–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78export class Select<T> extends React.PureComponent<ISelectProps<T>, ISelectState> {
79 public static displayName = `${DISPLAYNAME_PREFIX}.Select`;
80
81 public static ofType<T>() {
82 return Select as new (props: ISelectProps<T>) => Select<T>;
83 }
84
85 public state: ISelectState = { isOpen: false };
86
87 private TypedQueryList = QueryList.ofType<T>();
88
89 private inputEl: HTMLInputElement | IRefObject<HTMLInputElement> | null = null;
90 private queryList: QueryList<T> | null = null;
91 private previousFocusedElement: HTMLElement | undefined;
92 private refHandlers = {
93 input: isRefObject<HTMLInputElement>(this.props.inputProps?.inputRef)
94 ? (this.inputEl = this.props.inputProps!.inputRef)
95 : (ref: HTMLInputElement | null) => {
96 this.inputEl = ref;
97 (this.props.inputProps?.inputRef as IRefCallback<HTMLInputElement>)?.(ref);
98 },
99 queryList: (ref: QueryList<T> | null) => (this.queryList = ref),
100 };
101
102 public render() {
103 // omit props specific to this component, spread the rest.
104 const { filterable, inputProps, popoverProps, ...restProps } = this.props;
105
106 return (
107 <this.TypedQueryList
108 {...restProps}
109 onItemSelect={this.handleItemSelect}
110 ref={this.refHandlers.queryList}
111 renderer={this.renderQueryList}
112 />
113 );
114 }
115
116 public componentDidUpdate(_prevProps: ISelectProps<T>, prevState: ISelectState) {
117 if (this.state.isOpen && !prevState.isOpen && this.queryList != null) {
118 this.queryList.scrollActiveItemIntoView();
119 }
120 }
121
122 private renderQueryList = (listProps: IQueryListRendererProps<T>) => {
123 // not using defaultProps cuz they're hard to type with generics (can't use <T> on static members)
124 const { filterable = true, disabled = false, inputProps = {}, popoverProps = {} } = this.props;
125
126 const input = (
127 <InputGroup
128 leftIcon="search"
129 placeholder="Filter..."
130 rightElement={this.maybeRenderClearButton(listProps.query)}
131 {...inputProps}
132 inputRef={this.refHandlers.input}
133 onChange={listProps.handleQueryChange}
134 value={listProps.query}
135 />

Callers

nothing calls this directly

Calls 8

isRefObjectFunction · 0.90
getRefFunction · 0.90
preventDefaultMethod · 0.80
focusMethod · 0.80
setQueryMethod · 0.80
ofTypeMethod · 0.45

Tested by

no test coverage detected