Skip to content

Commit 96d57b0

Browse files
devin-ai-integration[bot]SScorp
authored andcommitted
feat(CountryFlag): add role prop for accessibility customization
Co-Authored-By: Jozef Képesi <[email protected]>
1 parent 1bf0bb9 commit 96d57b0

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

packages/orbit-components/src/CountryFlag/CountryFlag.stories.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const meta: Meta<typeof CountryFlag> = {
1616
name: "Country",
1717
code: CODES.ANYWHERE,
1818
size: SIZES.SMALL,
19+
role: "img",
1920
},
2021

2122
argTypes: {
@@ -31,6 +32,12 @@ const meta: Meta<typeof CountryFlag> = {
3132
type: "select",
3233
},
3334
},
35+
role: {
36+
options: ["img", "presentation", "none"],
37+
control: {
38+
type: "select",
39+
},
40+
},
3441
},
3542
};
3643

packages/orbit-components/src/CountryFlag/README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ After adding import into your project you can use it simply like:
1616

1717
Table below contains all types of the props available in CountryFlag component.
1818

19-
| Name | Type | Default | Description |
20-
| :------- | :-------------- | :------------ | :----------------------------------- |
21-
| code | [`enum`](#enum) | `"undefined"` | Code for the displayed country flag. |
22-
| dataTest | `string` | | Optional prop for testing purposes. |
23-
| id | `string` | | Set `id` for `CountryFlag` |
24-
| name | `string` | | The name for the flag. |
25-
| size | [`enum`](#enum) | `"medium"` | The size of the CountryFlag. |
19+
| Name | Type | Default | Description |
20+
| :------- | :----------------------------------------------- | :------------ | :----------------------------------- |
21+
| code | [`enum`](#enum) | `"undefined"` | Code for the displayed country flag. |
22+
| dataTest | `string` | | Optional prop for testing purposes. |
23+
| id | `string` | | Set `id` for `CountryFlag` |
24+
| name | `string` | | The name for the flag. |
25+
| role | `React.HTMLAttributes<HTMLImageElement>["role"]` | `"img"` | ARIA role for the flag image. |
26+
| size | [`enum`](#enum) | `"medium"` | The size of the CountryFlag. |
2627

2728
### enum
2829

packages/orbit-components/src/CountryFlag/__tests__/index.test.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ describe("CountryFlag", () => {
8181
);
8282
expect(wrapper).toHaveStyle({ width: "16px", height: "9px" });
8383
});
84+
85+
it("should support custom role", () => {
86+
render(<CountryFlag code="us" name="United States" role="presentation" />);
87+
expect(screen.getByRole("presentation")).toBeInTheDocument();
88+
});
8489
});

packages/orbit-components/src/CountryFlag/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getCountryProps(code?: string, name?: string) {
1717
return { code: countryCode, name: countryName };
1818
}
1919

20-
const CountryFlag = ({ dataTest, size = SIZES.MEDIUM, id, ...props }: Props) => {
20+
const CountryFlag = ({ dataTest, size = SIZES.MEDIUM, id, role = "img", ...props }: Props) => {
2121
const { code, name } = getCountryProps(props.code, props.name);
2222

2323
const width = SIZE_WIDTHS[size];
@@ -40,6 +40,7 @@ const CountryFlag = ({ dataTest, size = SIZES.MEDIUM, id, ...props }: Props) =>
4040
data-test={dataTest}
4141
src={src}
4242
srcSet={srcSet}
43+
role={role}
4344
/>
4445
<div className="rounded-50 shadow-country-flag absolute inset-0 block size-full" />
4546
</div>

packages/orbit-components/src/CountryFlag/types.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Type definitions for @kiwicom/orbit-components
22
// Project: http://github.com/kiwicom/orbit
33

4+
import type * as React from "react";
5+
46
import type * as Common from "../common/types";
57

68
export type Size = "small" | "medium";
@@ -9,4 +11,5 @@ export interface Props extends Common.Globals {
911
readonly code?: string;
1012
readonly name?: string;
1113
readonly size?: Size;
14+
readonly role?: React.HTMLAttributes<HTMLImageElement>["role"];
1215
}

0 commit comments

Comments
 (0)