-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: prevent onPress from being called when RadioGroup is read only #9433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,6 +276,28 @@ describe('RadioGroup', () => { | |
| expect(label).toHaveClass('readonly'); | ||
| }); | ||
|
|
||
| it('should not trigger onPress when read only', async () => { | ||
| let onPress = jest.fn(); | ||
| let className = ({isReadOnly}) => isReadOnly ? 'readonly' : ''; | ||
| let {getByRole, getAllByRole} = renderGroup({isReadOnly: true, className}, {className, onPress}); | ||
|
|
||
| let group = getByRole('radiogroup'); | ||
| let label = getAllByRole('radio')[0].closest('label'); | ||
|
|
||
| expect(group).toHaveAttribute('aria-readonly'); | ||
| expect(group).toHaveClass('readonly'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a little weird, and possibly a different issue, why are the group and the label both getting the readonly class?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i just copied that from the previous test to confirm the ready only part so different issue? |
||
|
|
||
| expect(label).toHaveAttribute('data-readonly'); | ||
| expect(label).toHaveClass('readonly'); | ||
|
|
||
| let radios = getAllByRole('radio'); | ||
| let radioA = radios[0]; | ||
| let labelA = radioA.closest('label'); | ||
|
|
||
| await user.click(labelA); | ||
| expect(onPress).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should support invalid state', () => { | ||
| let className = ({isInvalid}) => isInvalid ? 'invalid' : null; | ||
| let {getByRole, getAllByRole} = renderGroup({isInvalid: true, className}, {className}); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh... useToggle seems more like the bug, it was done to prevent us from allowing the value to be changed by our manual handling, it wasn't done to prevent onPress from being called.
I would argue that onPress should be called, interactions aren't prevented by readonly, for example, an input. You can click into those and select and copy text. You just can't change it. I'll ask a question in the Issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm yeah i think that's a valid argument. fine to close this issue if we think it this is the correct behavior