Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility improvements #595

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/box-container/box-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ export const BoxContainer = ({
<Handle
onClick={onHandleClick}
type="button"
aria-label={showExpanded ? "Collapse" : "Expand"}
data-testid={subComponentTestIds?.handle || "handle"}
>
<HandleIconContainer $expanded={showExpanded}>
<HandleIcon />
<HandleIcon aria-hidden />
</HandleIconContainer>
</Handle>
)
Expand Down
2 changes: 1 addition & 1 deletion src/feedback-rating/feedback-rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const FeedbackRating = (props: FeedbackRatingProps): JSX.Element => {
<MainContainer {...otherProps}>
{bannerSrc && (
<Image
data-testid="feedback-banner-image"
src={bannerSrc}
alt=""
aria-label="banner image"
onError={(event) =>
(event.currentTarget.style.display = "none")
}
Expand Down
3 changes: 1 addition & 2 deletions src/form/form-label-addon.style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const TriggerArea = styled.button`
`;

export const AddonWrapper = styled.div`
padding-left: 0.25rem;
display: inline;
position: relative;
width: fit-content;
`;
36 changes: 14 additions & 22 deletions src/form/form-label-addon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ICircleFillIcon } from "@lifesg/react-icons/i-circle-fill";
import { RefObject } from "react";
import { PopoverTrigger } from "../popover-v2/popover-trigger";
import { AddonWrapper, TriggerArea } from "./form-label-addon.style";
import { PopoverInline } from "../popover-v2";
import { AddonWrapper } from "./form-label-addon.style";
import { FormLabelAddonProps } from "./types";

// =============================================================================
Expand All @@ -26,26 +26,18 @@ export const PopoverAddon = ({
// =========================================================================
// RENDER FUNCTION
// =========================================================================
const renderIcon = () => {
if (icon) {
return icon;
} else {
return <ICircleFillIcon id={`${type}-icon`} />;
}
};

return (
<PopoverTrigger
trigger="click"
id={id}
data-testid={testId}
popoverContent={content}
rootNode={rootNode}
zIndex={zIndex}
>
<AddonWrapper>
<TriggerArea>{renderIcon()}</TriggerArea>
</AddonWrapper>
</PopoverTrigger>
<AddonWrapper>
<PopoverInline
trigger="click"
id={id}
data-testid={testId}
popoverContent={content}
rootNode={rootNode}
zIndex={zIndex}
icon={icon ?? <ICircleFillIcon data-testid={`${type}-icon`} />}
ariaLabel="More info"
/>
</AddonWrapper>
);
};
2 changes: 2 additions & 0 deletions src/histogram-slider/histogram-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const HistogramSlider = ({
showRangeLabels,
rangeLabelPrefix,
rangeLabelSuffix,
ariaLabels,
onChange,
onChangeEnd,
renderEmptyView,
Expand Down Expand Up @@ -133,6 +134,7 @@ export const HistogramSlider = ({
value={selection}
disabled={disabled}
readOnly={readOnly}
ariaLabels={ariaLabels}
onChange={handleChange}
onChangeEnd={handleChangeEnd}
/>
Expand Down
1 change: 1 addition & 0 deletions src/histogram-slider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface HistogramSliderProps {
showRangeLabels?: boolean | undefined;
rangeLabelPrefix?: string | undefined;
rangeLabelSuffix?: string | undefined;
ariaLabels?: [string, string] | undefined;
renderRangeLabel?: ((value: number) => React.ReactNode) | undefined;
/** Called on every selection change. Returns the value in the format `[start, end]` */
onChange?: ((value: [number, number]) => void) | undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/notification-banner/notification-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export const NBComponent = ({
data-testid={formatId("dismiss-button", testId)}
focusHighlight={false}
type="button"
aria-label="Dismiss notification"
>
<StyledIcon />
<StyledIcon aria-hidden />
</StyledIconButton>
);

Expand Down
1 change: 1 addition & 0 deletions src/otp-input/otp-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const OtpInput = ({
"otp-input",
dataTestId
)}
aria-label={`Enter OTP character ${index + 1}`}
key={index}
ref={(el) => (inputRefs.current[index] = el)}
type="text"
Expand Down
8 changes: 7 additions & 1 deletion src/popover-v2/popover-inline/popover-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PopoverInlineProps } from "../types";
import { StyledIcon, StyledText } from "./popover-inline.styles";

export const PopoverInline = ({
ariaLabel,
content,
icon,
underlineStyle = "default",
Expand All @@ -12,6 +13,8 @@ export const PopoverInline = ({
// =========================================================================
// RENDER FUNCTIONS
// =========================================================================
const hasContent = !!content;

return (
<PopoverTrigger {...otherProps}>
<StyledText
Expand All @@ -20,9 +23,12 @@ export const PopoverInline = ({
tabIndex={0}
$defaultStyle={underlineStyle}
$hoverStyle={underlineHoverStyle}
aria-label={ariaLabel ?? (hasContent ? undefined : "More info")}
>
{content}
{icon && <StyledIcon $standalone={!content}>{icon}</StyledIcon>}
{icon && (
<StyledIcon $standalone={!hasContent}>{icon}</StyledIcon>
)}
</StyledText>
</PopoverTrigger>
);
Expand Down
1 change: 1 addition & 0 deletions src/popover-v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type PopoverInlineStyle = "default" | "underline" | "underline-dashed";

export interface PopoverInlineProps
extends Omit<PopoverV2TriggerProps, "children"> {
ariaLabel?: string | undefined;
content?: React.ReactNode | undefined;
icon?: JSX.Element | undefined;
underlineStyle?: PopoverInlineStyle | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/progress-indicator/progress-indicator.style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Wrapper = styled.div`
}
`;

export const Content = styled.nav`
export const Content = styled.div`
display: flex;
flex-basis: 0;
justify-content: space-between;
Expand Down
12 changes: 4 additions & 8 deletions src/progress-indicator/progress-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ export const ProgressIndicator = <T,>({
const highlighted = stepIndex <= currentIndex;

return (
<Indicator
key={stepIndex}
aria-label={getAriaLabel(stepIndex, currentIndex)}
id={getId(stepIndex, currentIndex)}
>
<Indicator key={stepIndex} id={getId(stepIndex, currentIndex)}>
<IndicatorBar highlighted={highlighted}></IndicatorBar>
</Indicator>
);
Expand All @@ -82,17 +78,18 @@ export const ProgressIndicator = <T,>({
const renderStepTitleDesktop = () => {
return steps.map((step: T, stepIndex: number) => {
const highlighted = stepIndex <= currentIndex;
const fontWeight = stepIndex === currentIndex ? "bold" : "regular";
const current = stepIndex === currentIndex;
const fontWeight = current ? "bold" : "regular";

return (
<Indicator
key={stepIndex}
aria-label={getAriaLabel(stepIndex, currentIndex)}
id={`${getId(stepIndex, currentIndex)}-title`}
>
<IndicatorTitleDesktop
highlighted={highlighted}
weight={fontWeight}
aria-current={current}
>
{getDisplayValue(step)}
</IndicatorTitleDesktop>
Expand All @@ -105,7 +102,6 @@ export const ProgressIndicator = <T,>({
return (
<Indicator
key={currentIndex}
aria-label={getAriaLabel(currentIndex, currentIndex)}
id={getId(currentIndex, currentIndex)}
>
<IndicatorTitleMobile
Expand Down
8 changes: 7 additions & 1 deletion src/select-histogram/select-histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export const SelectHistogram = ({
value,
...otherProps
}: SelectHistogramProps): JSX.Element => {
const { interval, bins = [], renderEmptyView } = histogramSlider;
const {
interval,
bins = [],
renderEmptyView,
ariaLabels,
} = histogramSlider;
// =============================================================================
// CONST, STATE
// =============================================================================
Expand Down Expand Up @@ -193,6 +198,7 @@ export const SelectHistogram = ({
onChangeEnd={onSliderChangeEnd}
showRangeLabels={false}
renderEmptyView={renderEmptyView}
ariaLabels={ariaLabels}
/>
</HistogramSliderDropdownContainer>
);
Expand Down
2 changes: 1 addition & 1 deletion src/select-histogram/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DropdownAlignmentType } from "../shared/dropdown-wrapper";

export type SelectHistogramSliderProps = Pick<
HistogramSliderProps,
"bins" | "interval" | "renderEmptyView"
"bins" | "interval" | "renderEmptyView" | "ariaLabels"
>;

export interface SelectHistogramProps {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/internal-calendar/calendar-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ const Component = (
</HeaderInputDropdown>
<HeaderArrows>
<HeaderArrowButton
aria-label="Previous month"
data-testid="left-arrow-btn"
disabled={isLeftArrowDisabled()}
focusHighlight={false}
Expand All @@ -377,6 +378,7 @@ const Component = (
<ArrowLeft />
</HeaderArrowButton>
<HeaderArrowButton
aria-label="Next month"
data-testid="right-arrow-btn"
disabled={isRightArrowDisabled()}
focusHighlight={false}
Expand Down
3 changes: 2 additions & 1 deletion src/sidenav/sidenav-group.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const Container = styled.ul`
flex-direction: column;
align-items: center;
width: 100%;
list-style: none;
`;

export const Divider = styled.div`
export const Divider = styled.li`
margin: 0.5rem 0;
width: 6.5rem;
height: 1px;
Expand Down
1 change: 1 addition & 0 deletions src/tab/tab-link-chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const TabLinkChain = ({
return (
<ChainItem
key={index}
role="none"
$active={isActive}
ref={isActive ? activeLinkRef : null}
>
Expand Down
5 changes: 5 additions & 0 deletions stories/form/form-histogram-slider/props-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ const DATA: ApiTableSectionProps[] = [
description: "Function to render custom selection range labels",
propTypes: ["(value: number) => React.ReactNode"],
},
{
name: "ariaLabels",
description: "The user-friendly description of each thumb",
propTypes: ["[string, string]"],
},
{
name: "onChange",
description: (
Expand Down
5 changes: 5 additions & 0 deletions stories/form/form-select-histogram/props-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ const DATA: ApiTableSectionProps[] = [
"A custom display if there are no results across any of the bins",
propTypes: ["() => React.ReactNode"],
},
{
name: "ariaLabels",
description: "The user-friendly description of each thumb",
propTypes: ["[string, string]"],
},
],
},
...SHARED_FORM_PROPS_DATA,
Expand Down
2 changes: 1 addition & 1 deletion tests/feedback-rating/feedback-rating.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const getSubmitButton = (label?: string): HTMLElement => {
};

const getBannerImg = (): HTMLElement => {
return screen.getByRole("img", { name: "banner image" });
return screen.getByTestId("feedback-banner-image");
};

// =============================================================================
Expand Down