From 3077ba767d12d193b9187290c98c077ab9ce8e5d Mon Sep 17 00:00:00 2001 From: Carlos Wu Date: Wed, 28 Sep 2022 10:27:36 +0100 Subject: [PATCH] fix: fire onChange handler when toggle and id are passed This commit attempts to fix onChange not firing when `id` is passed. Previouly, there was a fix to prevent two clicks from being fired by stopping propagation, but in my example I was able to prevent two clicks from being fired using `e.preventDefault` --- .../Radio/Types/RadioOnchangeExample.js | 22 +++++++++++++++++++ docs/src/examples/addons/Radio/Types/index.js | 5 +++++ src/modules/Checkbox/Checkbox.js | 15 ++++++++----- test/specs/modules/Checkbox/Checkbox-test.js | 16 -------------- 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 docs/src/examples/addons/Radio/Types/RadioOnchangeExample.js diff --git a/docs/src/examples/addons/Radio/Types/RadioOnchangeExample.js b/docs/src/examples/addons/Radio/Types/RadioOnchangeExample.js new file mode 100644 index 0000000000..b15d25c621 --- /dev/null +++ b/docs/src/examples/addons/Radio/Types/RadioOnchangeExample.js @@ -0,0 +1,22 @@ +import React, { useState } from 'react' +import { Radio } from 'semantic-ui-react' + +const RadioOnChange = () => { + const [profileState, setProfileState] = useState(false) + + const handleChange = () => setProfileState(!profileState) + + return ( + <> +

{profileState ? 'Profile is visible' : 'Profile is invisible'}

+ + + ) +} + +export default RadioOnChange diff --git a/docs/src/examples/addons/Radio/Types/index.js b/docs/src/examples/addons/Radio/Types/index.js index 6e3524d089..f8f1e05543 100644 --- a/docs/src/examples/addons/Radio/Types/index.js +++ b/docs/src/examples/addons/Radio/Types/index.js @@ -6,6 +6,11 @@ import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const RadioTypesExamples = () => ( + { ) }) - it('is not called when on change when "id" is passed', () => { - const onChange = sandbox.spy() - wrapperMount() - - wrapper.find('label').simulate('mouseup') - wrapper.find('label').simulate('click') - onChange.should.have.not.been.called() - }) - it('is called when click is done on nested element', () => { const onChange = sandbox.spy() wrapperMount(Foo }} onChange={onChange} />) @@ -408,13 +399,6 @@ describe('Checkbox', () => { input: ['click'], }, }, - { - description: 'click on label with "id": fires on mouse click', - events: { - label: ['mouseup', 'click'], - }, - id: 'foo', - }, { description: 'click on input with "id": fires on mouse click', events: {