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

update SwitchField to allow updates on controlled component #1302

Merged
merged 6 commits into from
Feb 14, 2022

Conversation

jacoblogan
Copy link
Contributor

Description of changes

Update SwitchField logic to allow modifications of the checked state through the onChange 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

  • PR description included
  • yarn test passes
  • Tests are updated
  • Relevant documentation is changed or added (and PR referenced)

switch

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2022

🦋 Changeset detected

Latest commit: fa12e74

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ui-react Patch

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

@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:27 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:27 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:27 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:27 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:45 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:45 Inactive
@jacoblogan jacoblogan requested a deployment to ci February 11, 2022 17:45 Abandoned
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:46 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 11, 2022 17:46 Inactive
Copy link
Contributor

@joebuono joebuono left a 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.
Copy link
Contributor

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.

Copy link
Contributor

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.

@joebuono joebuono temporarily deployed to ci February 11, 2022 18:18 Inactive
@joebuono joebuono temporarily deployed to ci February 11, 2022 18:18 Inactive
@joebuono joebuono temporarily deployed to ci February 11, 2022 18:18 Inactive
@joebuono joebuono temporarily deployed to ci February 11, 2022 18:18 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:16 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:16 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:16 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:16 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:49 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:49 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:49 Inactive
@jacoblogan jacoblogan temporarily deployed to ci February 14, 2022 17:49 Inactive
@jacoblogan jacoblogan merged commit 732aee9 into main Feb 14, 2022
@jacoblogan jacoblogan deleted the switchfield-controlled-edit branch February 14, 2022 22:56
@github-actions github-actions bot mentioned this pull request Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants