From d6fb04c69835547a1145939f3c6590cb68ee14a9 Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Mon, 19 Sep 2022 12:24:46 +0200 Subject: [PATCH] SONAR-17295 Fixing scroll issue when searching for saml related properties --- .../authentication/SamlAuthentication.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthentication.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthentication.tsx index 05a8a9b44bf..e0ccf340bfa 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthentication.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlAuthentication.tsx @@ -87,19 +87,31 @@ class SamlAuthentication extends React.PureComponent< componentDidMount() { const { definitions } = this.props; const keys = definitions.map(definition => definition.key).join(','); + // Added setTimeout to make sure the component gets updated before scrolling + setTimeout(() => { + if (location.hash) { + this.scrollToSearchedField(); + } + }); this.loadSettingValues(keys); } componentDidUpdate(prevProps: SamlAuthenticationProps) { const { location } = this.props; - if (this.formFieldRef.current && prevProps.location.hash !== location.hash) { + if (prevProps.location.hash !== location.hash) { + this.scrollToSearchedField(); + } + } + + scrollToSearchedField = () => { + if (this.formFieldRef.current) { this.formFieldRef.current.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); } - } + }; onFieldChange = (id: string, value: string | boolean) => { const { settingValue, dirtyFields } = this.state; -- 2.39.5