Skip to content

Commit

Permalink
A11y Documentation: Time Picker - Internationalization (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
moathabuhamad-cengage authored Oct 9, 2024
1 parent 463c3f4 commit 04f09e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/a11y-timePicker-shortcut.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-docs': patch
---

fix(TimePicker): improve TimePicker internationalization example.
18 changes: 16 additions & 2 deletions website/react-magma-docs/src/pages/api/time-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export function Example() {

return (
<>
<TimePicker labelText="Time Due" onChange={handleOnChange} value={timeValue} />
<TimePicker
labelText="Time Due"
onChange={handleOnChange}
value={timeValue}
/>
<br />
<Button onClick={() => handleOnChange(undefined)}>Clear Time</Button>
</>
Expand Down Expand Up @@ -174,6 +178,8 @@ export function Example() {

## Internationalization

The `TimePicker` component supports internationalization through the `I18nContext`. You can provide translations for the following properties `hoursAriaLabel`, `minutesAriaLabel` ,`amButtonAriaLabel`, `pmButtonAriaLabel`, `amSelectedAnnounce` and `pmSelectedAnnounce` Additionally, the `labelText` prop affects the aria-label of the input, ensuring that screen readers announce the correct label, making the component accessible for users in different languages.

```tsx
import React from 'react';
import { I18nContext, defaultI18n, TimePicker } from 'react-magma-dom';
Expand All @@ -185,9 +191,17 @@ export function Example() {
value={{
...defaultI18n,
locale: zhCN,
timePicker: {
hoursAriaLabel: '小时',
minutesAriaLabel: '分钟',
amButtonAriaLabel: '上午已选中。要切换到下午,请按 p 或回车键。',
pmButtonAriaLabel: '下午已选中。要切换到上午,请按 a 或回车键。',
amSelectedAnnounce: '现在选择上午',
pmSelectedAnnounce: '现在选择下午',
},
}}
>
<TimePicker labelText="International Time" />
<TimePicker labelText="到期时间" />
<TimePicker
labelText="International Time with Passed in Value"
value="01:30 下午"
Expand Down

2 comments on commit 04f09e8

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.