-
Notifications
You must be signed in to change notification settings - Fork 114
Add read-only Switch #5902
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
base: main
Are you sure you want to change the base?
Add read-only Switch #5902
Changes from 5 commits
5a76029
5e28883
d7c47f9
640867c
4a56201
191e0cf
1698c9b
ca41212
8c267b7
7c32ca5
f458d85
636df55
eb8cde0
e3ec559
4ac75a9
567fb33
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 |
|---|---|---|
|
|
@@ -175,4 +175,21 @@ describe("GIVEN a Switch", () => { | |
| cy.findByRole("switch").should("be.focused"); | ||
| cy.findByRole("switch").should("be.checked"); | ||
| }); | ||
|
|
||
| describe("WHEN readOnly is true", () => { | ||
| it("THEN should not be toggle if clicked", () => { | ||
| cy.mount(<Switch readOnly />); | ||
| cy.findByRole("switch").should("not.be.checked"); | ||
| cy.findByRole("switch").realClick(); | ||
| cy.findByRole("switch").should("not.be.checked"); | ||
| }); | ||
|
|
||
| it("THEN should not be toggle when pressing the Space key", () => { | ||
| cy.mount(<Switch readOnly />); | ||
| cy.findByRole("switch").should("not.be.checked"); | ||
|
Contributor
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. no test of focus but it's something we call out as a differentiator between disabled?
Contributor
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. read-only attribute as well ?
Contributor
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. Good point thanks, I've included them in the tests |
||
| cy.realPress("Tab"); | ||
| cy.realPress("Space"); | ||
| cy.findByRole("switch").should("not.be.checked"); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,32 @@ | |
| width: calc((var(--salt-size-selectable) + var(--salt-spacing-25) + var(--salt-size-fixed-100)) * 2); | ||
| } | ||
|
|
||
| .saltSwitch-readOnly { | ||
| cursor: var(--salt-cursor-text); | ||
| } | ||
|
|
||
| .saltSwitch-readOnly .saltSwitch-track, | ||
| .saltSwitch-readOnly:hover .saltSwitch-track { | ||
| border-color: var(--salt-selectable-borderColor-readonly); | ||
| color: var(--salt-content-primary-foreground); | ||
| } | ||
|
|
||
| .saltSwitch-readOnly:hover .saltSwitch-thumb { | ||
| border-color: var(--salt-selectable-borderColor-readonly); | ||
| } | ||
|
|
||
| .saltSwitch-readOnly .saltSwitch-thumb, | ||
| .saltSwitch-readOnly.saltSwitch-checked .saltSwitch-thumb { | ||
| background: var(--salt-container-primary-background); | ||
| border: var(--salt-size-fixed-100) var(--salt-borderStyle-dashed) var(--salt-selectable-borderColor-readonly); | ||
| } | ||
|
|
||
| .saltSwitch-readOnly .saltSwitch-input:focus-visible + .saltSwitch-track, | ||
| .saltSwitch-readOnly .saltSwitch-input:focus-visible + .saltSwitch-track .saltSwitch-thumb { | ||
| border-color: var(--salt-selectable-borderColor-readonly); | ||
| color: var(--salt-content-primary-foreground); | ||
| } | ||
|
|
||
| @media (prefers-reduced-motion) { | ||
| .saltSwitch-input:focus-visible + .saltSwitch-track .saltSwitch-thumb, | ||
| .saltSwitch:hover .saltSwitch-thumb { | ||
|
|
@@ -121,6 +147,10 @@ | |
| border: 0; | ||
| } | ||
|
|
||
| .salt-density-high .saltSwitch-readOnly .saltSwitch-thumb { | ||
|
Contributor
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. Why is this needed?
Contributor
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. Right above sets border to zero for some reason
Contributor
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 assume it's to do with sizing, could you check with the designers if what is there meets the expected outcome please
Contributor
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. Figma doesn't have a stroke on the switch thumb in all the densities. Read-only states look correct though. |
||
| border: var(--salt-size-fixed-100) var(--salt-borderStyle-dashed) var(--salt-selectable-borderColor-readonly); | ||
| } | ||
|
|
||
| /* Styles applied when switch is inside a form field with label left or right, ensuring alignment with base / input height */ | ||
| .saltFormField-labelRight .saltSwitch, | ||
| .saltFormField-labelLeft .saltSwitch { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.