From 1483f4cdbda399390a6ec477659a61651fa28fb7 Mon Sep 17 00:00:00 2001 From: Daniel Sil Date: Thu, 7 Nov 2024 16:48:15 +0100 Subject: [PATCH] feat(Seat): add aria-labelledby string prop It receives a string of id(s) --- packages/orbit-components/src/Seat/README.md | 15 +++++++++++++-- .../orbit-components/src/Seat/Seat.stories.tsx | 6 +++--- packages/orbit-components/src/Seat/index.tsx | 11 ++++++----- packages/orbit-components/src/Seat/types.d.ts | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/orbit-components/src/Seat/README.md b/packages/orbit-components/src/Seat/README.md index 27cd7b3a35..91f2711bc4 100644 --- a/packages/orbit-components/src/Seat/README.md +++ b/packages/orbit-components/src/Seat/README.md @@ -16,8 +16,19 @@ After adding import into your project you can use it simply like: Table below contains all types of the props available in Seat component. -| title | `string` | | Adds title title to svg element. Announced by screen readers. | -| description | `string` | | Adds description to svg element. Announced by screen readers. | +| Name | Type | Default | Description | +| :-------------- | :---------------------- | :-------- | :------------------------------------------------------------------- | +| dataTest | `string` | | Optional prop for testing purposes. | +| id | `string` | | `id` of the element. | +| size | [`enum`](#modal-enum) | `medium` | Size of Seat component. | +| type | [`enum`](#modal-enum) | `default` | Visual type of Seat. If `unavailable`, the element becomes disabled. | +| price | `string` | | Price of Seat. Displayed as text underneath the svg. | +| label | `string` | | Label text inside of a Seat. Not announced by **screen readers**. | +| selected | `boolean` | | Displays Seat as selected. | +| onClick | `() => void \| Promise` | | Function for handling onClick event. | +| aria-labelledby | `string` | | Id(s) of elements that announce the component to screen readers. | +| title | `string` | | Adds title title to svg element. Announced by screen readers. | +| description | `string` | | Adds description to svg element. Announced by screen readers. | ## SeatLegend diff --git a/packages/orbit-components/src/Seat/Seat.stories.tsx b/packages/orbit-components/src/Seat/Seat.stories.tsx index a3db430d39..992a4663c2 100644 --- a/packages/orbit-components/src/Seat/Seat.stories.tsx +++ b/packages/orbit-components/src/Seat/Seat.stories.tsx @@ -14,7 +14,7 @@ const meta: Meta = { parameters: { info: "Seat components stories. Visit Orbit.Kiwi for more detailed guidelines.", controls: { - exclude: ["onClick"], + exclude: ["onClick", "aria-labelledby"], }, }, @@ -40,7 +40,7 @@ type Story = StoryObj; export const Default: Story = { parameters: { controls: { - exclude: ["type", "size", "title", "description", "selected", "onClick"], + exclude: ["aria-labelledby", "type", "size", "selected"], }, }, }; @@ -72,7 +72,7 @@ export const Legend: Story = { parameters: { info: "SeatLegend component. Check Orbit.Kiwi for more detailed guidelines.", controls: { - exclude: ["size", "title", "description", "selected", "onClick"], + exclude: ["size", "selected", "aria-labelledby"], }, }, diff --git a/packages/orbit-components/src/Seat/index.tsx b/packages/orbit-components/src/Seat/index.tsx index 408f6a9776..beadcc2ef9 100644 --- a/packages/orbit-components/src/Seat/index.tsx +++ b/packages/orbit-components/src/Seat/index.tsx @@ -24,10 +24,11 @@ const Seat = ({ label, title, description, + "aria-labelledby": ariaLabelledBy = "", }: Props) => { const randomId = useRandomIdSeed(); - const titleId = randomId("title"); - const descrId = randomId("descr"); + const titleId = title ? randomId("title") : ""; + const descrId = description ? randomId("descr") : ""; const clickable = type !== TYPES.UNAVAILABLE; return ( @@ -46,12 +47,12 @@ const Seat = ({ > - {title} - {description} + {title && {title}} + {description && {description}} {size === SIZE_OPTIONS.SMALL ? ( diff --git a/packages/orbit-components/src/Seat/types.d.ts b/packages/orbit-components/src/Seat/types.d.ts index 8f2790dd3a..ae4f585541 100644 --- a/packages/orbit-components/src/Seat/types.d.ts +++ b/packages/orbit-components/src/Seat/types.d.ts @@ -19,6 +19,7 @@ export interface Props extends Common.Globals { readonly size?: Size; readonly title?: string; readonly description?: string; + readonly "aria-labelledby"?: string; readonly onClick?: Common.Callback; readonly selected?: boolean; readonly label?: React.ReactNode;