Skip to content

Commit

Permalink
feat(Checkbox): deprecate default_state property (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored and tujoworker committed May 31, 2023
1 parent 03a6bd0 commit a022de3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 36 deletions.
12 changes: 1 addition & 11 deletions packages/dnb-eufemia/src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default class Checkbox extends React.PureComponent {
label_position: PropTypes.oneOf(['left', 'right']),
title: PropTypes.string,
element: PropTypes.node,
default_state: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), // Deprecated
checked: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
disabled: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
id: PropTypes.string,
Expand Down Expand Up @@ -94,7 +93,6 @@ export default class Checkbox extends React.PureComponent {
label_position: null,
title: null,
element: 'input',
default_state: null, // Deprecated
checked: null,
disabled: null,
id: null,
Expand Down Expand Up @@ -130,14 +128,7 @@ export default class Checkbox extends React.PureComponent {
static getDerivedStateFromProps(props, state) {
if (state._listenForPropChanges) {
if (props.checked !== state._checked) {
if (
props.default_state !== null &&
typeof state.checked === 'undefined'
) {
state.checked = Checkbox.parseChecked(props.default_state)
} else {
state.checked = Checkbox.parseChecked(props.checked)
}
state.checked = Checkbox.parseChecked(props.checked)
}
}
state._listenForPropChanges = true
Expand Down Expand Up @@ -217,7 +208,6 @@ export default class Checkbox extends React.PureComponent {
class: _className,

id: _id, // eslint-disable-line
default_state: _default_state, // eslint-disable-line
checked: _checked, // eslint-disable-line
children, // eslint-disable-line
on_change, // eslint-disable-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,6 @@ describe('Checkbox component', () => {
expect(my_event.mock.calls[0][0].checked).toBe(true)
})

it('uses "default_value" as the startup state – if given', () => {
expect(
mount(<Component default_state={true} />)
.find('input')
.instance().checked
).toBe(true)

expect(
mount(<Component default_state={true} checked={false} />)
.find('input')
.instance().checked
).toBe(true)

const Comp = mount(<Component default_state={false} checked={true} />)
expect(Comp.find('input').instance().checked).toBe(false)

Comp.find('input').simulate('change')
expect(Comp.find('input').instance().checked).toBe(true)
})

it('does handle controlled vs uncontrolled state properly', () => {
const ControlledVsUncontrolled = () => {
const [checked, setChecked] = React.useState(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`Checkbox component have to match snapshot 1`] = `
"className": "className",
"custom_element": {},
"custom_method": [Function],
"default_state": "default_state",
"disabled": "disabled",
"element": "element",
"global_status_id": "global_status_id",
Expand Down Expand Up @@ -49,7 +48,6 @@ exports[`Checkbox component have to match snapshot 1`] = `
className={null}
custom_element={null}
custom_method={null}
default_state={null}
disabled={null}
element="input"
global_status_id={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ exports[`ToggleButton component have to match snapshot 1`] = `
custom_element={null}
custom_method={null}
data-checked="false"
default_state={null}
disabled="disabled"
element="span"
global_status_id={null}
Expand Down Expand Up @@ -202,7 +201,6 @@ exports[`ToggleButton component have to match snapshot 1`] = `
custom_element={null}
custom_method={null}
data-checked="false"
default_state={null}
disabled="disabled"
element="span"
global_status_id={null}
Expand Down Expand Up @@ -270,7 +268,6 @@ exports[`ToggleButton component have to match snapshot 1`] = `
custom_element={null}
custom_method={null}
data-checked="false"
default_state={null}
disabled="disabled"
element="span"
global_status_id={null}
Expand Down

0 comments on commit a022de3

Please sign in to comment.