Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paragon
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
paragon
Commits
c913e080
Commit
c913e080
authored
Aug 17, 2017
by
Sarah Fischmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing onChange and proptypes
parent
b82b0a76
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
26 deletions
+29
-26
.storybook/__snapshots__/Storyshots.test.js.snap
+4
-4
src/CheckBox/CheckBox.stories.jsx
+1
-1
src/CheckBox/CheckBox.test.jsx
+8
-10
src/CheckBox/index.jsx
+16
-11
No files found.
.storybook/__snapshots__/Storyshots.test.js.snap
View file @
c913e080
...
...
@@ -10,7 +10,7 @@ exports[`Storyshots CheckBox basic usage 1`] = `
disabled={false}
id="asInput1"
name="checkbox"
onC
lick
={[Function]}
onC
hange
={[Function]}
type="checkbox"
/>
<label
...
...
@@ -31,7 +31,7 @@ exports[`Storyshots CheckBox call a function 1`] = `
disabled={false}
id="asInput7"
name="checkbox"
onC
lick
={[Function]}
onC
hange
={[Function]}
type="checkbox"
/>
<label
...
...
@@ -52,7 +52,7 @@ exports[`Storyshots CheckBox default checked 1`] = `
disabled={false}
id="asInput5"
name="checkbox"
onC
lick
={[Function]}
onC
hange
={[Function]}
type="checkbox"
/>
<label
...
...
@@ -73,7 +73,7 @@ exports[`Storyshots CheckBox disabled 1`] = `
disabled={true}
id="asInput3"
name="checkbox"
onC
lick
={[Function]}
onC
hange
={[Function]}
type="checkbox"
/>
<label
...
...
src/CheckBox/CheckBox.stories.jsx
View file @
c913e080
...
...
@@ -32,6 +32,6 @@ storiesOf('CheckBox', module)
<
CheckBox
name=
"checkbox"
label=
"check out the console"
onChange
State
=
{
()
=>
console
.
log
(
'the checkbox changed state'
)
}
onChange=
{
()
=>
console
.
log
(
'the checkbox changed state'
)
}
/>
));
src/CheckBox/CheckBox.test.jsx
View file @
c913e080
...
...
@@ -28,11 +28,11 @@ describe('<CheckBox />', () => {
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
true
);
wrapper
.
find
(
'[type="checkbox"]'
).
simulate
(
'c
lick
'
);
wrapper
.
find
(
'[type="checkbox"]'
).
simulate
(
'c
hange
'
);
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
false
);
expect
(
wrapper
.
find
(
'[aria-checked=true]'
).
exists
()).
toEqual
(
true
);
wrapper
.
find
(
'[type="checkbox"]'
).
simulate
(
'c
lick
'
);
wrapper
.
find
(
'[type="checkbox"]'
).
simulate
(
'c
hange
'
);
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[aria-checked=true]'
).
exists
()).
toEqual
(
false
);
});
...
...
@@ -43,12 +43,12 @@ describe('<CheckBox />', () => {
<
CheckBox
name=
"checkbox"
label=
"check me out!"
onChange
State
=
{
spy
}
onChange=
{
spy
}
/>,
);
expect
(
spy
).
toHaveBeenCalledTimes
(
0
);
wrapper
.
find
(
'input'
).
simulate
(
'c
lick
'
);
wrapper
.
find
(
'input'
).
simulate
(
'c
hange
'
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
});
...
...
@@ -64,7 +64,7 @@ describe('<CheckBox />', () => {
expect
(
wrapper
.
find
(
'[defaultChecked=true]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[aria-checked=true]'
).
exists
()).
toEqual
(
true
);
wrapper
.
find
(
'input'
).
simulate
(
'c
lick
'
);
wrapper
.
find
(
'input'
).
simulate
(
'c
hange
'
);
expect
(
wrapper
.
find
(
'[defaultChecked=false]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
true
);
});
...
...
@@ -78,11 +78,9 @@ describe('<CheckBox />', () => {
/>,
);
expect
(
wrapper
.
find
(
'[defaultChecked=false]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
props
().
disabled
).
toEqual
(
true
);
wrapper
.
find
(
'input'
).
simulate
(
'click'
);
expect
(
wrapper
.
find
(
'[defaultChecked=false]'
).
exists
()).
toEqual
(
true
);
expect
(
wrapper
.
find
(
'[aria-checked=false]'
).
exists
()).
toEqual
(
true
);
wrapper
.
find
(
'input'
).
simulate
(
'change'
);
expect
(
wrapper
.
props
().
disabled
).
toEqual
(
true
);
});
});
src/CheckBox/index.jsx
View file @
c913e080
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
asInput
,
{
inputProps
}
from
'../asInput'
;
import
asInput
from
'../asInput'
;
import
newId
from
'../utils/newId'
;
class
Check
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
handleClick
=
this
.
handleClick
.
bind
(
this
);
if
(
this
.
props
.
onChangeState
)
{
this
.
onChangeState
=
this
.
props
.
onChangeState
.
bind
(
this
);
}
this
.
onChange
=
this
.
onChange
.
bind
(
this
);
const
id
=
newId
(
'checkbox'
);
this
.
state
=
{
...
...
@@ -19,13 +17,11 @@ class Check extends React.Component {
};
}
handleClick
(
)
{
onChange
(
event
)
{
this
.
setState
({
checked
:
!
this
.
state
.
checked
,
});
if
(
this
.
onChangeState
)
{
this
.
onChangeState
();
}
this
.
props
.
onChange
(
event
);
}
...
...
@@ -39,18 +35,27 @@ class Check extends React.Component {
name=
{
props
.
name
}
defaultChecked=
{
this
.
state
.
checked
}
aria
-
checked=
{
this
.
state
.
checked
}
onC
lick=
{
this
.
handleClick
}
onC
hange=
{
this
.
onChange
}
disabled=
{
props
.
disabled
}
/>
);
}
}
Check
.
propTypes
=
inputProps
;
Check
.
propTypes
=
{
checked
:
PropTypes
.
bool
,
onChange
:
PropTypes
.
func
,
};
Check
.
defaultProps
=
{
checked
:
false
,
onChange
:
()
=>
{},
};
const
CheckBox
=
asInput
(
Check
,
false
);
CheckBox
.
propTypes
=
{
...
CheckBox
.
propTypes
,
...
Check
.
propTypes
,
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment