Skip to content

Commit 8437dd9

Browse files
author
Edward Xiao
committed
- more test and change <Select/> value to internalValue.
1 parent 38455d9 commit 8437dd9

File tree

9 files changed

+51
-14
lines changed

9 files changed

+51
-14
lines changed

lib/components/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/components/react-inputs-validation.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/react-inputs-validation.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/react-inputs-validation.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-inputs-validation",
3-
"version": "4.1.9",
3+
"version": "4.2.0",
44
"description": "React form input validation components",
55
"main": "index.js",
66
"repository": {
@@ -29,7 +29,7 @@
2929
"scripts": {
3030
"test": "NODE_ENV=test jest",
3131
"test:coverage": "npm run tslint && npm run jslint && npm test -- --coverage",
32-
"test_single": "node_modules/.bin/jest Checkbox.js --coverage",
32+
"test_single": "node_modules/.bin/jest Select.js --coverage",
3333
"prepublish": "npm run test:coverage",
3434
"jslint": "eslint ./src",
3535
"tslint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
@@ -46,7 +46,7 @@
4646
"server_prod": "node_modules/.bin/webpack-dev-server --config ./webpack/production.config.js",
4747
"clean": "rimraf dist lib",
4848
"compile_webpack": "npm run clean && npm run build_umd_global && npm run build_umd_global_min && npm run build_umd_local",
49-
"compile": "npm run clean && npm run compile_webpack"
49+
"compile": "npm run clean && npm run compile_webpack && rm ./lib/components/*.css"
5050
},
5151
"peerDependencies": {
5252
"react": "^16.8.6",

src/__tests__/Select.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { memo, useState } from 'react';
22
import { expect as chaiExpect } from 'chai';
33
import { configure, mount } from 'enzyme';
44
import Adapter from 'enzyme-adapter-react-16';
@@ -239,6 +239,41 @@ describe('Select component', () => {
239239
).toEqual('success');
240240
});
241241

242+
const LIST1 = [{ id: 'us', name: 'US' }, { id: 'ca', name: 'CA' }];
243+
const LIST2 = [{ id: 'uk', name: 'UK' }, { id: 'fr', name: 'France' }];
244+
const MyComponent = memo(() => {
245+
const stateOptionList = useState(LIST1);
246+
const stateCurId = useState(LIST1[0].id);
247+
return (
248+
<div>
249+
<Select
250+
value={stateCurId[0]}
251+
onBlur={() => {}}
252+
optionList={stateOptionList[0]}
253+
onChange={res => {
254+
stateCurId[1](res.id);
255+
}}
256+
/>
257+
<div
258+
id="changeList"
259+
onClick={() => {
260+
stateOptionList[1](LIST2);
261+
}}
262+
>
263+
change list
264+
</div>
265+
<div id="stateCurId">{stateCurId[0]}</div>
266+
</div>
267+
);
268+
});
269+
270+
it('[update optionList]: Should change ', () => {
271+
const wrapper = mount(<MyComponent />);
272+
const $input = wrapper.find('input');
273+
wrapper.find('#changeList').simulate('click');
274+
expect($input.at(0).instance().value).toEqual(LIST2[0].id);
275+
});
276+
242277
it('[console.error REACT_INPUTS_VALIDATION_CUSTOM_ERROR_MESSAGE_EXAMPLE]: Should console.error REACT_INPUTS_VALIDATION_CUSTOM_ERROR_MESSAGE_EXAMPLE', () => {
243278
const restoreConsole = mockConsole();
244279
const wrapper = mount(<Select optionList={OPTION_LIST} onBlur={() => {}} validationOption={{ locale: 'foobar' }} />);

src/js/Inputs/Select.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ const component: React.FC<Props> = ({
535535
>
536536
<div ref={$wrapper} className={wrapperClass} style={customStyleWrapper}>
537537
<div className={containerClass} style={customStyleContainer}>
538-
<input type="hidden" value={value} className={inputClass} onChange={() => {}} {...attributesInput} />
538+
<input type="hidden" value={internalValue} className={inputClass} onChange={() => {}} {...attributesInput} />
539539
<div className={selectClass} style={customStyleSelect}>
540540
{selectorHtml}
541541
</div>
@@ -561,9 +561,12 @@ interface OptionProps {
561561
}
562562
export const Option: React.FC<OptionProps> = memo(
563563
({ index = -1, id = '', className = '', item = { id: '', name: '' }, customStyleOptionListItem = {}, onClick = () => {}, onMouseOver = () => {}, onMouseMove = () => {}, onMouseOut = () => {} }) => {
564-
const handleOnClick = useCallback((e: React.MouseEvent<HTMLElement>) => {
565-
onClick(item, e);
566-
}, [item]);
564+
const handleOnClick = useCallback(
565+
(e: React.MouseEvent<HTMLElement>) => {
566+
onClick(item, e);
567+
},
568+
[item],
569+
);
567570
const handleOnMouseOver = useCallback(() => {
568571
onMouseOver(index);
569572
}, []);

0 commit comments

Comments
 (0)