mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: prevent alt text from appearing if OIDC icon fail to load (#10792)
* fix: update alt text issue
This commit is contained in:
@@ -2,9 +2,10 @@ import Button from "@mui/material/Button";
|
||||
import GitHubIcon from "@mui/icons-material/GitHub";
|
||||
import KeyIcon from "@mui/icons-material/VpnKey";
|
||||
import Box from "@mui/material/Box";
|
||||
import { type FC } from "react";
|
||||
import { useId, type FC } from "react";
|
||||
import { Language } from "./SignInForm";
|
||||
import { type AuthMethods } from "api/typesGenerated";
|
||||
import { visuallyHidden } from "@mui/utils";
|
||||
|
||||
type OAuthSignInFormProps = {
|
||||
isSigningIn: boolean;
|
||||
@@ -12,16 +13,16 @@ type OAuthSignInFormProps = {
|
||||
authMethods?: AuthMethods;
|
||||
};
|
||||
|
||||
const iconStyles = {
|
||||
width: 16,
|
||||
height: 16,
|
||||
};
|
||||
|
||||
export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
|
||||
isSigningIn,
|
||||
redirectTo,
|
||||
authMethods,
|
||||
}) => {
|
||||
const iconStyles = {
|
||||
width: 16,
|
||||
height: 16,
|
||||
};
|
||||
|
||||
return (
|
||||
<Box display="grid" gap="16px">
|
||||
{authMethods?.github.enabled && (
|
||||
@@ -51,11 +52,7 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
|
||||
size="xlarge"
|
||||
startIcon={
|
||||
authMethods.oidc.iconUrl ? (
|
||||
<img
|
||||
alt="Open ID Connect icon"
|
||||
src={authMethods.oidc.iconUrl}
|
||||
css={iconStyles}
|
||||
/>
|
||||
<OidcIcon iconUrl={authMethods.oidc.iconUrl} />
|
||||
) : (
|
||||
<KeyIcon css={iconStyles} />
|
||||
)
|
||||
@@ -70,3 +67,24 @@ export const OAuthSignInForm: FC<OAuthSignInFormProps> = ({
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
type OidcIconProps = {
|
||||
iconUrl: string;
|
||||
};
|
||||
|
||||
function OidcIcon({ iconUrl }: OidcIconProps) {
|
||||
const hookId = useId();
|
||||
const oidcId = `${hookId}-oidc`;
|
||||
|
||||
// Even if the URL is defined, there is a chance that the request for the
|
||||
// image fails. Have to use blank alt text to avoid button from getting ugly
|
||||
// if that happens, but also still need a way to inject accessible text
|
||||
return (
|
||||
<>
|
||||
<img alt="" src={iconUrl} css={iconStyles} aria-labelledby={oidcId} />
|
||||
<div id={oidcId} css={{ ...visuallyHidden }}>
|
||||
Open ID Connect
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user