diff --git a/webapp/channels/src/components/setting_item.tsx b/webapp/channels/src/components/setting_item.tsx index 11bf69c480..4bc2bdeb6e 100644 --- a/webapp/channels/src/components/setting_item.tsx +++ b/webapp/channels/src/components/setting_item.tsx @@ -1,11 +1,11 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react'; -import type {ReactNode, RefObject} from 'react'; +import type {ReactNode} from 'react'; +import React, {useEffect, useRef} from 'react'; -import SettingItemMin from 'components/setting_item_min'; import type SettingItemMinComponent from 'components/setting_item_min'; +import SettingItemMin from 'components/setting_item_min'; type Props = { @@ -27,7 +27,7 @@ type Props = { /** * The setting UI when it is maximized (open) */ - max: ReactNode; + max?: ReactNode; // Props to pass through for SettingItemMin updateSection: (section: string) => void; @@ -41,37 +41,42 @@ type Props = { collapsedEditButtonWhenDisabled?: ReactNode; } -export default class SettingItem extends React.PureComponent { - minRef: RefObject; +const SettingItem = ({ + active, + areAllSectionsInactive, + section, + max, + updateSection, + title, + isDisabled, + describe, + collapsedEditButtonWhenDisabled, +}: Props) => { + const minRef = useRef(null); - constructor(props: Props) { - super(props); - - this.minRef = React.createRef(); - } - - componentDidUpdate(prevProps: Props) { + useEffect(() => { // We want to bring back focus to the edit button when the section is opened and then closed along with all sections are closed - if (!this.props.active && prevProps.active && this.props.areAllSectionsInactive) { - this.minRef.current?.focus(); + + if (!active && areAllSectionsInactive) { + minRef.current?.focus(); } + }, [active]); + + if (active) { + return <>{max}; } - render() { - if (this.props.active) { - return this.props.max; - } + return ( + + ); +}; - return ( - - ); - } -} +export default React.memo(SettingItem); diff --git a/webapp/channels/src/components/user_settings/display/__snapshots__/user_settings_display.test.tsx.snap b/webapp/channels/src/components/user_settings/display/__snapshots__/user_settings_display.test.tsx.snap index b194d5f2ec..5a1d7c9f7e 100644 --- a/webapp/channels/src/components/user_settings/display/__snapshots__/user_settings_display.test.tsx.snap +++ b/webapp/channels/src/components/user_settings/display/__snapshots__/user_settings_display.test.tsx.snap @@ -30,7 +30,7 @@ exports[`components/user_settings/display/UserSettingsDisplay should match snaps className="divider-dark first" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - - -