Skip to content

Commit 34fb8e0

Browse files
committed
fix(ui-date-input): fix DateInput2 not working with NVDA
Closes: INSTUI-4356 NVDA really does not like if we give role=listbox to a table, removing it fixes it getting stuck TEST PLAN: Try navigating a DateInput2 example with VO, NVDA, JAWS
1 parent e6e5a7b commit 34fb8e0

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

packages/ui-a11y-content/src/AccessibleContent/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ import { propTypes, allowedProps } from './props'
3333
import type { AccessibleContentProps } from './props'
3434

3535
/**
36-
---
37-
category: components/utilities
38-
---
39-
@module AccessibleContent
40-
**/
36+
* ---
37+
* category: components/utilities
38+
* ---
39+
* This component hides its children from screenreaders, they will read the text
40+
* specified by the `alt` prop instead
41+
* @module AccessibleContent
42+
*/
4143
class AccessibleContent extends Component<AccessibleContentProps> {
4244
static propTypes = propTypes
4345
static allowedProps = allowedProps

packages/ui-a11y-content/src/AccessibleContent/props.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ import type {
3131
} from '@instructure/shared-types'
3232

3333
type AccessibleContentOwnProps = {
34+
/**
35+
* The text that screenreaders will read. Will not be visible.
36+
*/
3437
alt?: string
3538

3639
/**
3740
* the element type to render the screen reader content as
3841
*/
3942
as: AsElementType
40-
43+
/**
44+
* Content that will be hidden from screenreaders (via `aria-hidden` set to `true`)
45+
*/
4146
children?: React.ReactNode
4247
}
4348

packages/ui-date-input/src/DateInput2/__new-tests__/DateInput2.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('<DateInput2 />', () => {
127127

128128
it('should not show calendar table by default', async () => {
129129
render(<DateInputExample />)
130-
const calendarTable = screen.queryByRole('listbox')
130+
const calendarTable = screen.queryByRole('table')
131131

132132
expect(calendarTable).not.toBeInTheDocument()
133133
})
@@ -141,8 +141,7 @@ describe('<DateInput2 />', () => {
141141
await userEvent.click(calendarButton)
142142

143143
await waitFor(() => {
144-
const calendarTable = screen.queryByRole('listbox')
145-
144+
const calendarTable = screen.queryByRole('table')
146145
expect(calendarTable).toBeInTheDocument()
147146
})
148147
})
@@ -258,7 +257,7 @@ describe('<DateInput2 />', () => {
258257
await userEvent.click(calendarButton)
259258

260259
await waitFor(() => {
261-
const calendarTable = screen.queryByRole('listbox')
260+
const calendarTable = screen.queryByRole('table')
262261

263262
expect(calendarTable).not.toBeInTheDocument()
264263
})

packages/ui-date-input/src/DateInput2/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ const DateInput2 = ({
316316
visibleMonth={selectedDate}
317317
locale={getLocale()}
318318
timezone={getTimezone()}
319-
role="listbox"
320319
renderNextMonthButton={
321320
<IconButton
322321
size="small"

packages/ui-react-utils/src/getElementType.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ interface PropsObject {
4141
* ---
4242
* category: utilities/react
4343
* ---
44-
* Get the React element type for a component.
44+
* Get the React element type for a component. It uses the following logic:
45+
* 1. type defined by the `as` prop
46+
* 2. type returned by the `getDefault()` parameter
47+
* 3. `<a>` if it has a `href` or `to` prop
48+
* 4. `<button>` if it has an `onClick` prop
49+
* 5. the component's defaultProp's `as` field
50+
* 6. `<span>` if none of the above
4551
*
4652
* @module getElementType
4753
* @param {ComponentType} Component

0 commit comments

Comments
 (0)