Skip to content

Commit a2afb8b

Browse files
committed
feat(IllustrationPrimitive): add role prop to improve accessibility
1 parent 31325bd commit a2afb8b

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

packages/orbit-components/src/primitives/IllustrationPrimitive/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ As with every primitive, you should have a good reason to use `IllustrationPrimi
2020

2121
Table below contains all types of the props available in IllustrationPrimitive component.
2222

23-
| Name | Type | Default | Description |
24-
| :------- | :--------------------------- | :--------- | :-------------------------------------------------------------------------------------------------------------------------- |
25-
| alt | `string` | | Optional property for passing own `alt` attribute to the DOM image element. By default, the `name` of illustration is used. |
26-
| dataTest | `string` | | Optional prop for testing purposes. |
27-
| id | `string` | | Set `id` for IllustrationPrimitive |
28-
| **name** | `string` | | Name for the displayed illustrationPrimitive. |
29-
| size | [`enum`](#enum) | `"medium"` | The size of the IllustrationPrimitive. |
30-
| margin | `string \| number \| Object` | | Utility property to set margin. |
23+
| Name | Type | Default | Description |
24+
| :------- | :--------------------------- | :--------------- | :--------------------------------------------------------------------------------------------------------------- |
25+
| alt | `string` | | Optional property for passing own `alt` attribute to the DOM image element. By default, an empty string is used. |
26+
| dataTest | `string` | | Optional prop for testing purposes. |
27+
| id | `string` | | Set `id` for IllustrationPrimitive |
28+
| **name** | `string` | | Name for the displayed illustrationPrimitive. |
29+
| size | [`enum`](#enum) | `"medium"` | The size of the IllustrationPrimitive. |
30+
| margin | `string \| number \| Object` | | Utility property to set margin. |
31+
| role | `img\|presentation` | `"presentation"` | Optional property for a role attribute. |
3132

3233
### enum
3334

packages/orbit-components/src/primitives/IllustrationPrimitive/__tests__/index.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("IllustrationPrimitive", () => {
2121
/>,
2222
);
2323

24-
const img = screen.getByRole("img");
24+
const img = screen.getByRole("presentation");
2525

2626
expect(img).toHaveStyle({ maxHeight: "90px" });
2727
expect(screen.getByAltText("Alternative text")).toBeInTheDocument();
@@ -36,8 +36,8 @@ describe("IllustrationPrimitive", () => {
3636
screen.getByAltText("");
3737
});
3838

39-
it("should have name in alt", () => {
40-
render(<IllustrationPrimitive name="Accommodation" />);
41-
screen.getByAltText("Accommodation");
39+
it("should have alt filled in", () => {
40+
render(<IllustrationPrimitive name="Accommodation" alt="Accommodation illustration" />);
41+
screen.getByAltText("Accommodation illustration");
4242
});
4343
});

packages/orbit-components/src/primitives/IllustrationPrimitive/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const baseURL = "//images.kiwi.com";
3939
const IllustrationPrimitive = ({
4040
name,
4141
alt,
42+
role = "presentation",
4243
margin,
4344
size = SIZE_OPTIONS.MEDIUM,
4445
dataTest,
@@ -63,10 +64,11 @@ const IllustrationPrimitive = ({
6364
srcSet={`${baseURL}/illustrations/0x${
6465
height * 2
6566
}/${illustrationPath} 2x, ${baseURL}/illustrations/0x${height * 3}/${illustrationPath} 3x`}
66-
alt={typeof alt === "string" ? alt : name}
67+
alt={alt}
6768
data-test={dataTest}
6869
id={id}
6970
style={cssVars}
71+
role={role}
7072
/>
7173
);
7274
};

packages/orbit-components/src/primitives/IllustrationPrimitive/types.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import type * as Common from "../../common/types";
77

88
export type Size = "extraSmall" | "small" | "medium" | "large" | "display";
99

10+
// Interface content is fetched from /src/Illustration/TYPESCRIPT_TEMPLATE.template
1011
export interface Props extends Common.Globals, Common.SpaceAfter {
1112
readonly size?: Size;
1213
readonly name: string;
1314
readonly margin?: React.CSSProperties["margin"] | Common.ObjectProperty;
1415
readonly alt?: string;
16+
readonly role?: "img" | "presentation";
1517
}

packages/orbit-components/src/primitives/Primitives.stories.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export const IllustrationPrimitive: Story = {
6464
size: SIZE_OPTIONS.MEDIUM,
6565
spaceAfter: SPACINGS_AFTER.SMALL,
6666
name: "Accommodation",
67+
alt: "Accommodation illustration",
68+
role: "presentation",
6769
},
6870

6971
argTypes: {
@@ -85,6 +87,12 @@ export const IllustrationPrimitive: Story = {
8587
type: "select",
8688
},
8789
},
90+
role: {
91+
options: ["img", "presentation"],
92+
control: {
93+
type: "select",
94+
},
95+
},
8896
},
8997
};
9098

@@ -150,7 +158,6 @@ export const ButtonPrimitive: Story = {
150158
},
151159
loading: false,
152160
padding: "0 10px 0 10px",
153-
role: "",
154161
spaceAfter: SPACINGS_AFTER.SMALL,
155162
submit: false,
156163
title: "Button title",

0 commit comments

Comments
 (0)