Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df4f34a

Browse files
authored
fix: prevent alt text from appearing if OIDC icon fail to load (#10792)
* fix: update alt text issue
1 parent fbec79f commit df4f34a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

site/src/pages/LoginPage/OAuthSignInForm.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ import Button from "@mui/material/Button";
22
import GitHubIcon from "@mui/icons-material/GitHub";
33
import KeyIcon from "@mui/icons-material/VpnKey";
44
import Box from "@mui/material/Box";
5-
import { type FC } from "react";
5+
import { useId, type FC } from "react";
66
import { Language } from "./SignInForm";
77
import { type AuthMethods } from "api/typesGenerated";
8+
import { visuallyHidden } from "@mui/utils";
89

910
type OAuthSignInFormProps = {
1011
isSigningIn: boolean;
1112
redirectTo: string;
1213
authMethods?: AuthMethods;
1314
};
1415

16+
const iconStyles = {
17+
width: 16,
18+
height: 16,
19+
};
20+
1521
export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
1622
isSigningIn,
1723
redirectTo,
1824
authMethods,
1925
}) => {
20-
const iconStyles = {
21-
width: 16,
22-
height: 16,
23-
};
24-
2526
return (
2627
<Box display="grid" gap="16px">
2728
{authMethods?.github.enabled && (
@@ -51,11 +52,7 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
5152
size="xlarge"
5253
startIcon={
5354
authMethods.oidc.iconUrl ? (
54-
<img
55-
alt="Open ID Connect icon"
56-
src={authMethods.oidc.iconUrl}
57-
css={iconStyles}
58-
/>
55+
<OidcIcon iconUrl={authMethods.oidc.iconUrl} />
5956
) : (
6057
<KeyIcon css={iconStyles} />
6158
)
@@ -70,3 +67,24 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
7067
</Box>
7168
);
7269
};
70+
71+
type OidcIconProps = {
72+
iconUrl: string;
73+
};
74+
75+
function OidcIcon({ iconUrl }: OidcIconProps) {
76+
const hookId = useId();
77+
const oidcId = `${hookId}-oidc`;
78+
79+
// Even if the URL is defined, there is a chance that the request for the
80+
// image fails. Have to use blank alt text to avoid button from getting ugly
81+
// if that happens, but also still need a way to inject accessible text
82+
return (
83+
<>
84+
<img alt="" src={iconUrl} css={iconStyles} aria-labelledby={oidcId} />
85+
<div id={oidcId} css={{ ...visuallyHidden }}>
86+
Open ID Connect
87+
</div>
88+
</>
89+
);
90+
}

0 commit comments

Comments
 (0)