Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: toggle when id is passed #4385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/src/examples/addons/Radio/Types/RadioOnchangeExample.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<p>{profileState ? 'Profile is visible' : 'Profile is invisible'}</p>
<Radio
id='profile-radio'
toggle
label='Make my profile visible'
onChange={handleChange}
/>
</>
)
}

export default RadioOnChange
5 changes: 5 additions & 0 deletions docs/src/examples/addons/Radio/Types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'

const RadioTypesExamples = () => (
<ExampleSection title='Types'>
<ComponentExample
title='Radio onChange'
description='Radio toggle should work when id is passed.'
examplePath='addons/Radio/Types/RadioOnchangeExample'
/>
<ComponentExample
title='Radio'
description='A radio for checking.'
Expand Down
15 changes: 9 additions & 6 deletions src/modules/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export default class Checkbox extends Component {
if (this.isClickFromMouse) {
this.isClickFromMouse = false

if (isLabelClick && !hasId) {
if (isLabelClick) {
// Prevents two clicks from being fired rom the "input" click: https://github.com/Semantic-Org/Semantic-UI-React/issues/3433
// and also allows onChange to fire https://github.com/Semantic-Org/Semantic-UI-React/issues/3737
e.preventDefault()
this.handleChange(e)
}

Expand All @@ -82,11 +85,11 @@ export default class Checkbox extends Component {
this.handleChange(e)
}

if (isLabelClick && hasId) {
// To prevent two clicks from being fired from the component we have to stop the propagation
// from the "input" click: https://github.com/Semantic-Org/Semantic-UI-React/issues/3433
e.stopPropagation()
}
// if (isLabelClick && hasId) {
// // To prevent two clicks from being fired from the component we have to stop the propagation
// // from the "input" click: https://github.com/Semantic-Org/Semantic-UI-React/issues/3433
// e.stopPropagation()
// }
}
}

Expand Down
16 changes: 0 additions & 16 deletions test/specs/modules/Checkbox/Checkbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,6 @@ describe('Checkbox', () => {
)
})

it('is not called when on change when "id" is passed', () => {
const onChange = sandbox.spy()
wrapperMount(<Checkbox id='foo' onChange={onChange} />)

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(<Checkbox label={{ children: <span>Foo</span> }} onChange={onChange} />)
Expand Down Expand Up @@ -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: {
Expand Down