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/docs(Switch): fix uncontrolled examples #7418

Merged
merged 2 commits into from
May 26, 2022

Conversation

kmcfaul
Copy link
Contributor

@kmcfaul kmcfaul commented May 13, 2022

What: Closes #7255

@tlabaj Did these work before? Uncontrolled inputs shouldn't be setting isChecked, and half of the example switches are redundant now that it works. I'm curious if this was meant as a static demo initially.

@patternfly-build
Copy link
Contributor

patternfly-build commented May 13, 2022

Copy link
Contributor

@jenny-s51 jenny-s51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great update @kmcfaul !! It's really cool that we can get an uncontrolled input by setting isChecked to null!

According to the react docs, it looks like we can specify an initial value using defaultChecked but leave subsequent updates uncontrolled.

I see some defaultChecked logic in Checkbox.tsx and Radio.tsx, both of which also have uncontrolled examples, maybe we can expose defaultChecked in the props and use it in a similar way here? WDYT?

@@ -176,19 +176,9 @@ import { Switch } from '@patternfly/react-core';
aria-label="Message when on"
label="Message when on"
labelOff="Message when off"
isChecked
isChecked={null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isChecked={null}
isChecked={null}
defaultChecked

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmcfaul I am not sure if it did work before. I would need tog look at the history

@@ -176,19 +176,9 @@ import { Switch } from '@patternfly/react-core';
aria-label="Message when on"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also update the aria-label when appropriate to demonstrate the intention? it's possible that, when it's uncontrolled, there are a few extra considerations to make to make sure the aria-label is meaningful. Like, what should we have the aria-label say if it wont change when the switch is on/off?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened issue #7468 for this issue as well as an issue I noticed with the aria-labelledby attribute.

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Katie, I think you were right, this probably never worked before. I would expected it to work like the checkbox or radio in that you do not need to pass isChecked to make it uncontrolled. I think we need to update the code so that is the case. We can also support isChecked being passed as null in order to not break people...

@tlabaj
Copy link
Contributor

tlabaj commented May 19, 2022

@kmcfaul it looks like this issue came up before, there was an attempt to fix it that was reverted. Here is the original issue #2791
See this related issue too
#2879

@thatblindgeye
Copy link
Contributor

I took the logic seen in the DataListCheck component to determine whether the isChecked or defaultChecked prop should be used on the inner input's checked attribute.

@thatblindgeye thatblindgeye requested review from jenny-s51 and tlabaj May 26, 2022 16:30
Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@jenny-s51 jenny-s51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍 Nice work on this @kmcfaul @thatblindgeye

@tlabaj tlabaj merged commit edb9843 into patternfly:main May 26, 2022
@patternfly-build
Copy link
Contributor

Your changes have been released in:

  • eslint-plugin-patternfly-react@4.56.4
  • @patternfly/react-catalog-view-extension@4.68.4
  • @patternfly/react-charts@6.70.4
  • @patternfly/react-code-editor@4.58.4
  • @patternfly/react-console@4.68.4
  • @patternfly/react-core@4.217.4
  • @patternfly/react-docs@5.78.4
  • @patternfly/react-icons@4.68.4
  • @patternfly/react-inline-edit-extension@4.62.4
  • demo-app-ts@4.177.4
  • @patternfly/react-integration@4.179.4
  • @patternfly/react-log-viewer@4.62.4
  • @patternfly/react-styles@4.67.4
  • @patternfly/react-table@4.86.4
  • @patternfly/react-tokens@4.69.4
  • @patternfly/react-topology@4.64.4
  • @patternfly/react-virtualized-extension@4.64.4
  • transformer-cjs-imports@4.55.4

Thanks for your contribution! 🎉

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.

Bug - [Switch] - [uncontrolled examples are not working]
6 participants