MCPcopy Create free account
hub / github.com/DTStack/molecule / Select

Class Select

src/components/select/select.tsx:54–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52const selectArrowClassName = getBEMElement(selectClassName, 'arrow');
53
54export class Select extends PureComponent<ISelectProps, IState> {
55 private contextView: IContextView;
56 public state: IState;
57 private selectElm: RefObject<HTMLDivElement>;
58 private selectInput: RefObject<HTMLInputElement>;
59
60 constructor(props) {
61 super(props);
62 this.contextView = useContextView({
63 shadowOutline: false,
64 });
65 this.state = this.getDefaultState(this.props);
66 this.selectElm = React.createRef();
67 this.selectInput = React.createRef();
68 }
69
70 static getDerivedStateFromProps(props, state) {
71 if (props.value !== state.value) {
72 return {
73 option: Select.getSelectOption(props),
74 };
75 }
76 return null;
77 }
78
79 public componentDidMount() {
80 this.contextView.onHide(() => {
81 if (this.state.isOpen) {
82 this.setState({
83 isOpen: false,
84 });
85 }
86 });
87 }
88
89 public componentWillUnmount() {
90 this.contextView.dispose();
91 }
92
93 private static getSelectOption(props) {
94 let defaultSelectedOption: ISelectOptionProps = {};
95 const defaultValue = props.value || props.defaultValue;
96 const options = Children.toArray(props.children);
97 for (const option of options) {
98 if (isValidElement(option)) {
99 const optionProps = option.props as ISelectOptionProps;
100 if (optionProps.value && optionProps.value === defaultValue) {
101 defaultSelectedOption = {
102 ...optionProps,
103 name:
104 optionProps.name ||
105 (optionProps.children as string),
106 };
107 break;
108 }
109 }
110 }
111 return defaultSelectedOption;

Callers

nothing calls this directly

Calls 7

getAttrFunction · 0.90
classNamesFunction · 0.90
cloneReactChildrenFunction · 0.90
setStateMethod · 0.80
hideMethod · 0.80
showMethod · 0.80
onSelectMethod · 0.65

Tested by

no test coverage detected