-
Notifications
You must be signed in to change notification settings - Fork 308
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
update SwitchField to allow updates on controlled component #1302
Conversation
…ation to reflect and display this change
🦋 Changeset detectedLatest commit: fa12e74 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Looking good. Just a reminder that we don't want to add changesets for docs updates because it messes up our release pipeline 👍
The `isChecked` property is a `boolean` value that defines if the switch is on or off. This is a boolean property and being set to either true or false will change this into a controlled switchField which can only be switched on or off using this controlled value. | ||
The `isChecked` property is a `boolean` value that defines if the switch is on or off. This is a boolean property and being set to either true or false will change this into a controlled switchField. | ||
If you would like to be able to toggle a controlled `SwitchField` through the click event of the `SwitchField` component, you will need to pass in an `onChange` event function which updates the controlled value. | ||
This is demonstrated in the example below. |
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.
Perhaps we can rephrase the above to avoid being redundant? Suggestion:
The isChecked
prop is a boolean
value that defines if the SwitchField is on or off.
If you would like to be able to toggle a controlled SwitchField
, you can pass in an onChange
event handler to update the controlled value.
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.
What if we had a section called 'Controlled component' or something, similar to what we do here: https://ui.docs.amplify.aws/components/togglebutton#controlled-component and talk about isChecked
and onChange
in the same paragraph.
Description of changes
Update
SwitchField
logic to allow modifications of the checked state through theonChange
handler. Also updated the documentation to reflect this change and display an example of the change.Issue #1286
Description of how you validated changes
Additional tests were added to capture the changed behavior and manually validated the behavior through the documentation site.
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.