Skip to content

Commit f5aa012

Browse files
Fedo Hagge-KubatKolja
authored andcommitted
fix(a11y): use useId for unique error IDs, guard error display during loading
1 parent b3b0593 commit f5aa012

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎superset-frontend/src/explore/components/ControlHeader.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { FC, ReactNode } from 'react';
19+
import { FC, ReactNode, useId } from 'react';
2020
import { t } from '@apache-superset/core/translation';
2121
import { css, useTheme, SupersetTheme } from '@apache-superset/core/theme';
2222
import { FormLabel, InfoTooltip, Tooltip } from '@superset-ui/core/components';
@@ -72,6 +72,8 @@ const ControlHeader: FC<ControlHeaderProps> = ({
7272
danger,
7373
}) => {
7474
const theme = useTheme();
75+
const uniqueId = useId();
76+
const errorId = `${name || uniqueId}-error`;
7577

7678
if (!label) {
7779
return null;
@@ -184,7 +186,7 @@ const ControlHeader: FC<ControlHeaderProps> = ({
184186
/>
185187
</Tooltip>
186188
<span
187-
id={`${name || 'control'}-error`}
189+
id={errorId}
188190
role="alert"
189191
css={css`
190192
position: absolute;

‎superset-frontend/src/features/alerts/AlertReportModal.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,8 +2126,9 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
21262126
label={isReport ? t('Report name') : t('Alert name')}
21272127
required
21282128
error={
2129+
currentAlert &&
21292130
validationStatus[Sections.General].hasErrors &&
2130-
!currentAlert?.name?.length
2131+
!currentAlert.name?.length
21312132
? isReport
21322133
? t('Report name is required')
21332134
: t('Alert name is required')
@@ -2149,8 +2150,9 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
21492150
label={t('Owners')}
21502151
required
21512152
error={
2153+
currentAlert &&
21522154
validationStatus[Sections.General].hasErrors &&
2153-
!currentAlert?.owners?.length
2155+
!currentAlert.owners?.length
21542156
? t('At least one owner is required')
21552157
: undefined
21562158
}

0 commit comments

Comments
 (0)