From a022de37661dcfec3df09638cfbb01986fa7d853 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 6 Jan 2023 15:26:05 +0100 Subject: [PATCH] feat(Checkbox): deprecate default_state property (#1863) --- .../src/components/checkbox/Checkbox.js | 12 +---------- .../checkbox/__tests__/Checkbox.test.js | 20 ------------------- .../__snapshots__/Checkbox.test.js.snap | 2 -- .../__snapshots__/ToggleButton.test.js.snap | 3 --- 4 files changed, 1 insertion(+), 36 deletions(-) diff --git a/packages/dnb-eufemia/src/components/checkbox/Checkbox.js b/packages/dnb-eufemia/src/components/checkbox/Checkbox.js index 477c5bf5835..c49105f782d 100644 --- a/packages/dnb-eufemia/src/components/checkbox/Checkbox.js +++ b/packages/dnb-eufemia/src/components/checkbox/Checkbox.js @@ -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, @@ -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, @@ -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 @@ -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 diff --git a/packages/dnb-eufemia/src/components/checkbox/__tests__/Checkbox.test.js b/packages/dnb-eufemia/src/components/checkbox/__tests__/Checkbox.test.js index 6781c3957f8..1162271f6c3 100644 --- a/packages/dnb-eufemia/src/components/checkbox/__tests__/Checkbox.test.js +++ b/packages/dnb-eufemia/src/components/checkbox/__tests__/Checkbox.test.js @@ -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() - .find('input') - .instance().checked - ).toBe(true) - - expect( - mount() - .find('input') - .instance().checked - ).toBe(true) - - const Comp = mount() - 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) diff --git a/packages/dnb-eufemia/src/components/checkbox/__tests__/__snapshots__/Checkbox.test.js.snap b/packages/dnb-eufemia/src/components/checkbox/__tests__/__snapshots__/Checkbox.test.js.snap index 9e0b4d3590c..36694d2c254 100644 --- a/packages/dnb-eufemia/src/components/checkbox/__tests__/__snapshots__/Checkbox.test.js.snap +++ b/packages/dnb-eufemia/src/components/checkbox/__tests__/__snapshots__/Checkbox.test.js.snap @@ -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", @@ -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} diff --git a/packages/dnb-eufemia/src/components/toggle-button/__tests__/__snapshots__/ToggleButton.test.js.snap b/packages/dnb-eufemia/src/components/toggle-button/__tests__/__snapshots__/ToggleButton.test.js.snap index ba23ae7332b..527e952b39b 100644 --- a/packages/dnb-eufemia/src/components/toggle-button/__tests__/__snapshots__/ToggleButton.test.js.snap +++ b/packages/dnb-eufemia/src/components/toggle-button/__tests__/__snapshots__/ToggleButton.test.js.snap @@ -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} @@ -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} @@ -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}