Skip to content

Commit 85b32d1

Browse files
committed
feat: Override TextField for improve accessibility
Add an ID to make label and helperText accessible to screen readers
1 parent 64a5fa4 commit 85b32d1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

react/MuiCozyTheme/TextField/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { forwardRef } from 'react'
2+
import MuiTextField from '@material-ui/core/TextField'
3+
4+
const TextField = forwardRef(({ children, ...props }, ref) => {
5+
// A11Y, https://v4.mui.com/api/text-field/#props
6+
const uuid = crypto.randomUUID()
7+
8+
return (
9+
<MuiTextField ref={ref} id={uuid} {...props}>
10+
{children}
11+
</MuiTextField>
12+
)
13+
})
14+
15+
TextField.displayName = 'TextField'
16+
17+
export default TextField

test/jestsetup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import '@testing-library/jest-dom/extend-expect'
22
import { configure, mount, shallow } from 'enzyme'
33
import Adapter from 'enzyme-adapter-react-16'
4+
import nodeCrypto from 'crypto'
45

56
configure({ adapter: new Adapter() })
67

8+
Object.defineProperty(global, 'crypto', {
9+
value: {
10+
randomUUID: () => nodeCrypto.randomUUID()
11+
}
12+
})
13+
714
global.mount = mount
815
global.shallow = shallow
916

0 commit comments

Comments
 (0)