Skip to content

Commit 7bac1f4

Browse files
committed
[DDW-880] Forward html attributes to input field
1 parent f4d6247 commit 7bac1f4

File tree

13 files changed

+4632
-5670
lines changed

13 files changed

+4632
-5670
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v2
8+
- name: Setup Node.js
9+
uses: actions/setup-node@v2
10+
with:
11+
node-version: '14'
812
- name: install modules
9-
run: yarn
13+
run: yarn --frozen-lock
1014
- name: run tests
1115
run: yarn test

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

__tests__/Input.test.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,31 @@ import { Input } from '../source/components/Input';
44
import { renderInSimpleTheme } from './helpers/theming';
55

66
test('Input renders correctly', () => {
7-
expect(renderInSimpleTheme(
8-
<Input />
9-
)).toMatchSnapshot();
7+
expect(renderInSimpleTheme(<Input />)).toMatchSnapshot();
108
});
119

1210
test('Input renders with placeholder', () => {
13-
expect(renderInSimpleTheme(
14-
<Input placeholder="0.0000" />
15-
)).toMatchSnapshot();
11+
expect(renderInSimpleTheme(<Input placeholder="0.0000" />)).toMatchSnapshot();
1612
});
1713

1814
test('Input renders with a value', () => {
19-
expect(renderInSimpleTheme(
20-
<Input value="there is value" />
21-
)).toMatchSnapshot();
15+
expect(
16+
renderInSimpleTheme(<Input value="there is value" />)
17+
).toMatchSnapshot();
2218
});
2319

2420
test('Input is readOnly', () => {
25-
expect(renderInSimpleTheme(
26-
<Input readOnly />
27-
)).toMatchSnapshot();
21+
expect(renderInSimpleTheme(<Input readOnly />)).toMatchSnapshot();
22+
});
23+
24+
test('Input renders with data-* attributes', () => {
25+
const wrapper = renderInSimpleTheme(<Input data-testid="testId" />);
26+
expect(wrapper.find('input').prop('data-testid')).toEqual('testId');
27+
});
28+
29+
test('Input renders label with htmlFor attribute', () => {
30+
const id = 'inputId';
31+
const wrapper = renderInSimpleTheme(<Input id={id} label="label" />);
32+
expect(wrapper.find('input').prop('id')).toEqual(id);
33+
expect(wrapper.find('label').prop('for')).toEqual(id);
2834
});

netlify.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
environment = { YARN_VERSION = "1.22.4", NODE_VERSION = "14.17.0" }

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"js": "babel source -d lib -s",
1111
"js:watch": "yarn js --watch",
1212
"lint": "eslint --format=node_modules/eslint-formatter-pretty source stories *.js",
13-
"prepare": "yarn clean && yarn build",
13+
"prepare": "yarn clean && yarn build && husky install",
1414
"sass": "node 'scripts/prepare-sass-files-for-publishing.js'",
1515
"sass:watch": "nodemon -e scss --watch source/themes --exec 'yarn sass'",
1616
"storybook": "start-storybook -p 6543 -c storybook --ci",
@@ -23,7 +23,7 @@
2323
"@tippyjs/react": "4.2.1",
2424
"create-react-context": "0.2.2",
2525
"fast-password-entropy": "1.1.1",
26-
"filter-react-dom-props": "0.0.2",
26+
"filter-invalid-dom-props": "2.1.0",
2727
"popper.js": "1.16.1",
2828
"react-modal": "3.1.12",
2929
"react-scrollbars-custom": "4.0.21"
@@ -71,11 +71,13 @@
7171
"extract-text-webpack-plugin": "3.0.2",
7272
"file-loader": "5.0.2",
7373
"flow-bin": "0.134.0",
74+
"husky": "7.0.4",
7475
"identity-obj-proxy": "3.0.0",
7576
"jest": "25.1.0",
7677
"jest-enzyme": "7.1.2",
78+
"lint-staged": "12.1.3",
7779
"lodash": "4.17.19",
78-
"node-sass": "4.13.1",
80+
"node-sass": "4.14.1",
7981
"nodemon": "1.12.1",
8082
"prettier": "2.0.5",
8183
"prettier-eslint": "9.0.1",
@@ -142,5 +144,13 @@
142144
"render prop",
143145
"skins",
144146
"themes"
145-
]
147+
],
148+
"lint-staged": {
149+
"*.js": "eslint --cache --fix",
150+
"*.{js,css,md}": "prettier --write"
151+
},
152+
"devEngines": {
153+
"node": ">=14.17.0",
154+
"yarn": "1.22.4"
155+
}
146156
}

source/components/FormField.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type FormFieldProps = {
1616
disabled?: boolean,
1717
error?: string | Element<any>,
1818
formFieldRef: ElementRef<*>,
19+
id?: string,
1920
isErrorHidden?: boolean,
2021
isErrorShown?: boolean,
2122
isShowingErrorOnFocus: boolean,

source/components/Input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type InputProps = {
2323
inputRef?: RefObject,
2424
showErrorState?: boolean,
2525
hideErrorState?: boolean,
26+
id?: string,
2627
isShowingErrorOnFocus: boolean,
2728
isShowingErrorOnHover: boolean,
2829
label?: string | Element<any>,

source/skins/simple/FormFieldSkin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function FormFieldSkin(props: Props) {
4040
aria-hidden
4141
className={props.theme[props.themeId].label}
4242
onClick={props.focusChild}
43+
htmlFor={props.id}
4344
>
4445
{props.label}
4546
</label>

source/skins/simple/InputSkin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const InputSkin = (props: Props) => {
5757
disabled={props.disabled}
5858
label={props.label}
5959
error={props.error}
60+
id={props.id}
6061
isShowingErrorOnHover={props.isShowingErrorOnHover}
6162
isShowingErrorOnFocus={props.isShowingErrorOnFocus}
6263
formFieldRef={props.inputRef}

0 commit comments

Comments
 (0)