-
Notifications
You must be signed in to change notification settings - Fork 20
[BOOKINGSG-9221][GZ] migrate radio button to linaria #1105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9e71786
[BOOKINGSG-9221][GZ] rename style filename
ghazwanmuhammad 06d233a
[BOOKINGSG-9221][GZ] migrate tokens
ghazwanmuhammad 0e7aad4
[BOOKINGSG-9221][GZ] convert styled interpolation to semantic data at…
ghazwanmuhammad c6a9755
[BOOKINGSG-9221][GZ] convert styled comopnents to linaria css
ghazwanmuhammad 96b57d2
[BOOKINGSG-9221][GZ] add unit test
ghazwanmuhammad f40c669
[BOOKINGSG-9221][GZ] cleanup selectors
ghazwanmuhammad 828b76e
[BOOKINGSG-9221][GZ] add visual test
ghazwanmuhammad fce0a11
[BOOKINGSG-9221][GZ] remove unused locators
ghazwanmuhammad 33dfcee
[BOOKINGSG-9221][GZ] add aria snapshot for radio button unchecked dis…
ghazwanmuhammad 60228a9
[BOOKINGSG-9221][GZ] refactor input classes
ghazwanmuhammad 11c6c6d
[BOOKINGSG-9221][GZ] extract out common icon styles
ghazwanmuhammad ef5cc15
[BOOKINGSG-9221][GZ] remove nested icon classes
ghazwanmuhammad 9d5e49d
[BOOKINGSG-9221][GZ] flatten locators & add spacing to the story
ghazwanmuhammad f383b7d
[BOOKINGSG-9221][GZ] group aria snapshot & add checked hover cases
ghazwanmuhammad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
e2e/nextjs-app/src/app/components/radio-button/focusable-when-disabled.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| "use client"; | ||
|
|
||
| import { RadioButton } from "@lifesg/react-design-system/radio-button"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [changeCount, setChangeCount] = useState(0); | ||
|
|
||
| return ( | ||
| <div className="story-column-container"> | ||
| <button data-testid="focus-start">Focus start</button> | ||
|
|
||
| <RadioButton | ||
| disabled | ||
| focusableWhenDisabled | ||
| checked={false} | ||
| onChange={() => setChangeCount((value) => value + 1)} | ||
| /> | ||
|
|
||
| <span data-testid="change-count">{changeCount}</span> | ||
| </div> | ||
| ); | ||
| } |
25 changes: 25 additions & 0 deletions
25
e2e/nextjs-app/src/app/components/radio-button/keyboard-navigation.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| "use client"; | ||
|
|
||
| import { RadioButton } from "@lifesg/react-design-system/radio-button"; | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Story() { | ||
| const [checked, setChecked] = useState(false); | ||
| const [changeCount, setChangeCount] = useState(0); | ||
|
|
||
| return ( | ||
| <div className="story-column-container"> | ||
| <button data-testid="focus-start">Focus start</button> | ||
|
|
||
| <RadioButton | ||
| checked={checked} | ||
| onChange={() => { | ||
| setChecked(true); | ||
| setChangeCount((value) => value + 1); | ||
| }} | ||
| /> | ||
|
|
||
| <span data-testid="change-count">{changeCount}</span> | ||
| </div> | ||
| ); | ||
| } |
46 changes: 46 additions & 0 deletions
46
e2e/nextjs-app/src/app/components/radio-button/variants.e2e.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| "use client"; | ||
|
|
||
| import { RadioButton } from "@lifesg/react-design-system/radio-button"; | ||
|
|
||
| export default function Story() { | ||
| return ( | ||
| <div className="story-column-container"> | ||
| <div className="story-row-container"> | ||
| <RadioButton | ||
| data-testid="radio-unchecked-default" | ||
| checked={false} | ||
| /> | ||
| <RadioButton data-testid="radio-checked-default" checked /> | ||
| <RadioButton data-testid="radio-unchecked-disabled" disabled /> | ||
| <RadioButton | ||
| data-testid="radio-checked-disabled" | ||
| checked | ||
| disabled | ||
| /> | ||
| </div> | ||
| <div className="story-row-container"> | ||
| <RadioButton | ||
| data-testid="radio-unchecked-small" | ||
| displaySize="small" | ||
| checked={false} | ||
| /> | ||
| <RadioButton | ||
| data-testid="radio-checked-small" | ||
| displaySize="small" | ||
| checked | ||
| /> | ||
| <RadioButton | ||
| data-testid="radio-unchecked-small-disabled" | ||
| disabled | ||
| displaySize="small" | ||
| /> | ||
| <RadioButton | ||
| data-testid="radio-checked-small-disabled" | ||
| checked | ||
| displaySize="small" | ||
| disabled | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
Binary file added
BIN
+1012 Bytes
...utton/__screenshots__/chromium/RadioButton-Variants--hover-checked-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.2 KB
...button/__screenshots__/chromium/RadioButton-Variants--hover-checked-enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+840 Bytes
.../radio-button/__screenshots__/chromium/RadioButton-Variants--hover-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+996 Bytes
...s/radio-button/__screenshots__/chromium/RadioButton-Variants--hover-enabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.07 KB
...omponents/radio-button/__screenshots__/chromium/RadioButton-Variants--mount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 150 additions & 0 deletions
150
e2e/tests/components/radio-button/radio-button.e2e.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { test as base, expect, Locator, Page } from "@playwright/test"; | ||
| import { AbstractStoryPage, compareScreenshot } from "../../utils"; | ||
|
|
||
| class StoryPage extends AbstractStoryPage { | ||
| protected readonly component = "radio-button"; | ||
|
|
||
| public readonly locators: { | ||
| radio: Locator; | ||
|
|
||
| radioUncheckedDefault: Locator; | ||
| radioCheckedDefault: Locator; | ||
| radioUncheckedDisabled: Locator; | ||
| radioCheckedDisabled: Locator; | ||
| focusStart: Locator; | ||
| changeCount: Locator; | ||
| }; | ||
|
|
||
| constructor(page: Page) { | ||
| super(page); | ||
|
|
||
| this.locators = { | ||
| radio: page.getByRole("radio"), | ||
|
|
||
| radioUncheckedDefault: page.getByTestId("radio-unchecked-default"), | ||
| radioCheckedDefault: page.getByTestId("radio-checked-default"), | ||
| radioUncheckedDisabled: page.getByTestId( | ||
| "radio-unchecked-disabled" | ||
| ), | ||
| radioCheckedDisabled: page.getByTestId("radio-checked-disabled"), | ||
| focusStart: page.getByTestId("focus-start"), | ||
| changeCount: page.getByTestId("change-count"), | ||
| }; | ||
| } | ||
|
|
||
| public getContainer(locator: Locator) { | ||
| return locator.locator("xpath=.."); | ||
| } | ||
| } | ||
|
|
||
| const test = base.extend<{ story: StoryPage }>({ | ||
| story: async ({ page }, runStory) => { | ||
| const story = new StoryPage(page); | ||
| await runStory(story); | ||
| }, | ||
| }); | ||
|
|
||
| test.describe("RadioButton", () => { | ||
| test.describe(() => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("variants"); | ||
| }); | ||
|
|
||
| test("Variants", async ({ story }) => { | ||
| await compareScreenshot(story, "mount"); | ||
|
|
||
| await expect(story.layout).toMatchAriaSnapshot(` | ||
| - radio | ||
| - radio [checked] | ||
| - radio [disabled] [checked] | ||
| - radio [disabled] | ||
| `); | ||
|
|
||
| await story.locators.radioUncheckedDefault.hover(); | ||
| await compareScreenshot(story, "hover-enabled", { | ||
| locator: story.getContainer( | ||
| story.locators.radioUncheckedDefault | ||
| ), | ||
| }); | ||
|
|
||
| await story.locators.radioCheckedDefault.hover(); | ||
| await compareScreenshot(story, "hover-checked-enabled", { | ||
| locator: story.getContainer(story.locators.radioCheckedDefault), | ||
| }); | ||
|
|
||
| await story.locators.radioUncheckedDisabled.hover(); | ||
| await compareScreenshot(story, "hover-disabled", { | ||
| locator: story.getContainer( | ||
| story.locators.radioUncheckedDisabled | ||
| ), | ||
| }); | ||
|
|
||
| await story.locators.radioCheckedDisabled.hover(); | ||
| await compareScreenshot(story, "hover-checked-disabled", { | ||
| locator: story.getContainer( | ||
| story.locators.radioCheckedDisabled | ||
| ), | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe(() => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("focusable-when-disabled"); | ||
| }); | ||
|
|
||
| test("Focusable when disabled", async ({ story }) => { | ||
| await test.step("Remains disabled", async () => { | ||
| await expect(story.locators.radio).toHaveAttribute( | ||
| "aria-disabled", | ||
| "true" | ||
| ); | ||
|
|
||
| await expect(story.locators.radio).toBeDisabled(); | ||
| }); | ||
|
|
||
| await test.step("Can receive focus", async () => { | ||
| await story.locators.focusStart.focus(); | ||
| await story.page.keyboard.press("Tab"); | ||
|
|
||
| await expect(story.locators.radio).toBeFocused(); | ||
| }); | ||
|
|
||
| await test.step("Do not trigger onChange", async () => { | ||
| await expect(story.locators.changeCount).toHaveText("0"); | ||
|
|
||
| await story.locators.radio.click({ | ||
| force: true, | ||
| }); | ||
|
|
||
| await story.page.keyboard.press("Space"); | ||
|
|
||
| await expect(story.locators.changeCount).toHaveText("0"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe(() => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("keyboard-navigation"); | ||
| }); | ||
|
|
||
| test("Keyboard navigation", async ({ story }) => { | ||
| await test.step("Radio can receive focus", async () => { | ||
| await story.locators.focusStart.focus(); | ||
| await story.page.keyboard.press("Tab"); | ||
|
|
||
| await expect(story.locators.radio).toBeFocused(); | ||
| }); | ||
|
|
||
| await test.step("Space key checks radio and fires onChange", async () => { | ||
| await expect(story.locators.changeCount).toHaveText("0"); | ||
|
|
||
| await story.page.keyboard.press("Space"); | ||
|
|
||
| await expect(story.locators.radio).toBeChecked(); | ||
| await expect(story.locators.changeCount).toHaveText("1"); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { css } from "@linaria/core"; | ||
|
|
||
| import { Colour, Motion } from "../theme"; | ||
|
|
||
| export const classes = {} as const; | ||
|
|
||
| export const container = css` | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| position: relative; | ||
|
|
||
| &[data-display-size="small"] { | ||
| height: 1.5rem; | ||
| width: 1.5rem; | ||
| } | ||
|
|
||
| &[data-display-size="default"] { | ||
| height: 2rem; | ||
| width: 2rem; | ||
| } | ||
| `; | ||
|
|
||
| export const icon = css` | ||
| height: 100%; | ||
| width: 100%; | ||
| transition: ${Motion["duration-150"]} ${Motion["ease-default"]}; | ||
|
qroll marked this conversation as resolved.
|
||
| `; | ||
|
|
||
| export const uncheckedIcon = css` | ||
| color: ${Colour["icon-subtle"]}; | ||
| `; | ||
|
|
||
| export const uncheckedIconDisabled = css` | ||
| color: ${Colour["icon-disabled-subtle"]}; | ||
| `; | ||
|
|
||
| export const checkedIcon = css` | ||
| color: ${Colour["icon-selected"]}; | ||
| `; | ||
|
|
||
| export const checkedIconDisabled = css` | ||
| color: ${Colour["icon-selected-disabled"]}; | ||
| `; | ||
|
|
||
| export const input = css` | ||
| position: absolute; | ||
| height: 100%; | ||
| width: 100%; | ||
| cursor: not-allowed; | ||
| z-index: 1; | ||
|
|
||
| appearance: none; | ||
| background: transparent; | ||
| border: none; | ||
| `; | ||
|
|
||
| export const inputActive = css` | ||
| cursor: pointer; | ||
|
|
||
| &:hover + svg { | ||
| @media (pointer: fine) { | ||
| color: ${Colour["icon-hover"]}; | ||
| } | ||
| } | ||
| `; | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.