diff --git a/gulpfile.js b/gulpfile.js index 02aa7ea507..98194607d2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires const createTasks = require('library-utils/gulp-tasks'); createTasks('arui-feather', { diff --git a/src/select/select.tsx b/src/select/select.tsx index d55a7ee80b..6381d232ed 100644 --- a/src/select/select.tsx +++ b/src/select/select.tsx @@ -8,7 +8,7 @@ import { DeepReadonly } from 'utility-types'; import { createCn } from 'bem-react-classname'; import { withTheme } from '../cn'; -import { Button } from '../button/button'; +import { Button } from '../button'; import IconButton from '../icon-button/icon-button'; import IconArrowDown from '../icon/ui/arrow-down'; import IconArrowUp from '../icon/ui/arrow-up'; @@ -16,11 +16,10 @@ import Menu from '../menu/menu'; import Mq from '../mq/mq'; import ThemedPopup from '../popup/popup'; import PopupHeader from '../popup-header/popup-header'; -import { ResizeSensor } from '../resize-sensor/resize-sensor'; +import { ResizeSensor } from '../resize-sensor'; import { HtmlElement } from '../lib/prop-types'; import keyboardCode from '../lib/keyboard-code'; -import performance from '../performance'; import scrollTo from '../lib/scroll-to'; import { SCROLL_TO_CORRECTION, SCROLL_TO_NORMAL_DURATION } from '../vars'; @@ -317,8 +316,7 @@ type SelectState = DeepReadonly<{ /** * Компонент выпадающего списка. */ -@performance(true) -export class Select extends React.Component { +export class Select extends React.PureComponent { protected cn = createCn('select'); static defaultProps: Partial = { @@ -342,7 +340,8 @@ export class Select extends React.Component { }; state: SelectState = { - hasGroup: false, + // eslint-disable-next-line max-len + hasGroup: this.props.options.some((option) => !!(option.type === 'group' && !!option.content)), isMobile: false, opened: !!this.props.opened, popupStyles: {}, @@ -368,13 +367,6 @@ export class Select extends React.Component { */ private awaitClosing = false; - // eslint-disable-next-line camelcase - UNSAFE_componentWillMount() { - this.setState({ - hasGroup: this.props.options.some((option) => !!(option.type === 'group' && !!option.content)), - }); - } - componentDidMount() { if (this.isAutoSelectRequired()) { this.selectFirstOption(); @@ -384,24 +376,19 @@ export class Select extends React.Component { this.updatePopupStyles(); } - // eslint-disable-next-line camelcase - UNSAFE_componentWillReceiveProps(nextProps) { + componentDidUpdate(prevProps: SelectProps) { this.setPopupTarget(); - this.updatePopupStyles(); - - if (this.state.opened && nextProps.disabled) { - this.toggleOpened(); - } - - this.setState({ - hasGroup: this.props.options.some((option) => !!(option.type === 'group' && !!option.content)), - }); - } - componentDidUpdate() { if (this.state.opened) { this.updatePopupStyles(); + if (this.props.disabled) { + this.toggleOpened(); + } } + // eslint-disable-next-line max-len + const hasGroup = prevProps.options.some((option) => option.type === 'group' && !!option.content); + + this.updateHasGroup(hasGroup); } render() { @@ -1041,8 +1028,10 @@ export class Select extends React.Component { if (this.props.equalPopupWidth) { popupStyles.maxWidth = buttonWidth; } - - this.setState({ popupStyles }); + if (this.state.popupStyles.maxWidth !== popupStyles.maxWidth + || this.state.popupStyles.minWidth !== popupStyles.minWidth) { + this.setState({ popupStyles }); + } }; private setPopupTarget = () => { @@ -1087,6 +1076,7 @@ export class Select extends React.Component { private isAutoSelectRequired() { const { mode, options, renderPopupOnFocus } = this.props; + // eslint-disable-next-line max-len return renderPopupOnFocus && mode === 'radio' && options.length > 0 && !this.hasCheckedItems(); } @@ -1112,6 +1102,12 @@ export class Select extends React.Component { return firstOption; } + + private updateHasGroup(hasGroup: boolean) { + if (this.state.hasGroup !== hasGroup) { + this.setState({ hasGroup }); + } + } } class ThemedSelect extends Select {} diff --git a/styleguide.config.js b/styleguide.config.js index 0dfabf1a43..3c86496b14 100644 --- a/styleguide.config.js +++ b/styleguide.config.js @@ -1,6 +1,6 @@ /* eslint strict: [0, "global"] */ /* eslint import/no-extraneous-dependencies: 0 */ - +/* eslint-disable */ 'use strict'; const path = require('path'); diff --git a/webpack.base.js b/webpack.base.js index 4ebc31d3a7..160992be4f 100644 --- a/webpack.base.js +++ b/webpack.base.js @@ -1,6 +1,8 @@ /* eslint import/no-extraneous-dependencies: [2, {"devDependencies": true}] */ +// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require('path'); +// eslint-disable-next-line @typescript-eslint/no-var-requires const webpack = require('webpack'); const QUERY = {