-
Notifications
You must be signed in to change notification settings - Fork 22
Dropdown #204
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
Dropdown #204
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d1dfe94
feat: add dropdown component
florianduros 2ca3ede
Close dropdown when clicked outside
florianduros 5964f99
Add doc to error props
florianduros e629fc8
Reworked dropdown
florianduros fdb8035
Move it out of form
florianduros e94ee1f
Add tests
florianduros 2d8928a
Fix figma link
florianduros 6e3cd63
Rename listRef into dropdownRef
florianduros 201a20e
Add keyboard support
florianduros ee0537f
Merge branch 'refs/heads/main' into florianduros/dropdown
florianduros 11c9947
Update icon path
florianduros cb464b4
Update jest tests
florianduros b16446e
Merge branch 'refs/heads/main' into florianduros/dropdown
florianduros c4a2d33
Add shortcut tests
florianduros eb79866
Move click listener
florianduros 3a425e3
Remove remaining console.log
florianduros bfddd36
Merge branch 'refs/heads/main' into florianduros/dropdown
florianduros 578b688
Fix lint error
florianduros 986ae30
Update copyright
florianduros 23e3548
Update jest snapshots
florianduros 4770080
Focus button when a value is selected
florianduros 36d222b
Update playwright snapshot
florianduros d6f7bb9
Focus item when displayed
florianduros cd325f9
Use 3 options instead of 2
florianduros 6782688
Update playwright tests
florianduros c9ada96
Remove conditional condition for ref
florianduros 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
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,56 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * / | ||
| */ | ||
| import { expect, test } from "@playwright/test"; | ||
|
|
||
| test.describe("Dropdown", () => { | ||
| test("should be able to select a value", async ({ page }) => { | ||
| await page.goto(`iframe.html?viewMode=story&id=dropdown--default`, { | ||
| waitUntil: "networkidle", | ||
| }); | ||
|
|
||
| await page.getByRole("combobox").click(); | ||
| await expect(page).toHaveScreenshot({ fullPage: true }); | ||
|
|
||
| await page.getByRole("option", { name: "Option 2" }).click(); | ||
| await expect(page.getByRole("combobox")).toHaveText("Option 2"); | ||
|
|
||
| await page.getByRole("combobox").click(); | ||
| await expect(page).toHaveScreenshot({ fullPage: true }); | ||
| }); | ||
|
|
||
| test("should to use keyboard shortcut", async ({ page }) => { | ||
| await page.goto(`iframe.html?viewMode=story&id=dropdown--default`, { | ||
| waitUntil: "networkidle", | ||
| }); | ||
|
|
||
| await page.getByRole("combobox").focus(); | ||
| await page.keyboard.press("ArrowDown"); | ||
|
|
||
| await expect(page).toHaveScreenshot({ fullPage: true }); | ||
|
|
||
| await page.keyboard.press("End"); | ||
| await expect(page.getByRole("option", { name: "Option 2" })).toBeFocused(); | ||
|
|
||
| await page.keyboard.press("Home"); | ||
| await expect(page.getByRole("option", { name: "Option 1" })).toBeFocused(); | ||
|
|
||
| await page.keyboard.press("Enter"); | ||
| await expect(page.getByRole("combobox")).toHaveText("Option 1"); | ||
| await expect(page).toHaveScreenshot({ fullPage: true }); | ||
| }); | ||
| }); | ||
Binary file added
BIN
+11.2 KB
...est.ts-snapshots/Dropdown-should-be-able-to-select-a-value-1-chromium-linux.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
+12.2 KB
...est.ts-snapshots/Dropdown-should-be-able-to-select-a-value-2-chromium-linux.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
+11.4 KB
...test.ts-snapshots/Dropdown-should-to-use-keyboard-shortcut-1-chromium-linux.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
+6.23 KB
...test.ts-snapshots/Dropdown-should-to-use-keyboard-shortcut-2-chromium-linux.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
+7.51 KB
playwright/visual.test.ts-snapshots/Dropdown-Default-1-chromium-linux.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
+6.37 KB
...right/visual.test.ts-snapshots/Dropdown-With-Default-Value-1-chromium-linux.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
+9.72 KB
playwright/visual.test.ts-snapshots/Dropdown-With-Error-1-chromium-linux.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
+9.4 KB
playwright/visual.test.ts-snapshots/Dropdown-With-Help-Label-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,147 @@ | ||
| /* | ||
|
florianduros marked this conversation as resolved.
|
||
| Copyright 2024 New Vector Ltd | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| label { | ||
| font: var(--cpd-font-body-md-medium); | ||
| margin-block-end: var(--cpd-space-1x); | ||
| } | ||
|
|
||
| button { | ||
| inline-size: 100%; | ||
| border: 1px solid var(--cpd-color-border-interactive-primary); | ||
| background: var(--cpd-color-bg-canvas-default); | ||
| border-radius: 0.5rem; | ||
| padding: var(--cpd-space-3x) var(--cpd-space-3x) var(--cpd-space-3x) | ||
| var(--cpd-space-4x); | ||
| box-sizing: border-box; | ||
| color: var(--cpd-color-text-primary); | ||
| font: var(--cpd-font-body-md-regular); | ||
| cursor: pointer; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| gap: var(--cpd-space-4x); | ||
|
|
||
| svg { | ||
| transition: transform 0.1s linear; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * When the dropdown is open, rotate the arrow icon | ||
| */ | ||
| button[aria-expanded="true"] { | ||
| svg { | ||
| transform: rotate(180deg); | ||
| } | ||
| } | ||
|
|
||
| button.placeholder { | ||
| color: var(--cpd-color-text-placeholder); | ||
| } | ||
|
|
||
| .border { | ||
| display: none; | ||
| border-inline-start: 1px solid var(--cpd-color-border-interactive-secondary); | ||
| border-inline-end: 1px solid var(--cpd-color-border-interactive-secondary); | ||
| block-size: var(--cpd-space-1x); | ||
| margin-block-start: calc(var(--cpd-space-1x) * -1); | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .content { | ||
| display: none; | ||
| position: relative; | ||
|
|
||
| ul { | ||
| /** | ||
| * To make the component going over the other elements | ||
| */ | ||
| position: absolute; | ||
| display: block; | ||
| inline-size: 100%; | ||
| background: var(--cpd-color-bg-canvas-default); | ||
| border: 1px solid var(--cpd-color-border-interactive-secondary); | ||
| border-block-start: 0; | ||
| border-end-start-radius: var(--cpd-space-4x); | ||
| border-end-end-radius: var(--cpd-space-4x); | ||
| box-sizing: border-box; | ||
| box-shadow: 0 4px 24px 0 rgb(27 29 34 / 10%); | ||
| margin: 0; | ||
| padding: 0; | ||
| padding-block-end: var(--cpd-space-4x); | ||
| cursor: pointer; | ||
|
|
||
| li { | ||
| list-style: none; | ||
| font: var(--cpd-font-body-md-medium); | ||
| padding: var(--cpd-space-3x) var(--cpd-space-4x); | ||
| border-block-end: 1px solid var(--cpd-color-gray-300); | ||
| color: var(--cpd-color-text-secondary); | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| gap: var(--cpd-space-4x); | ||
|
|
||
| @media (hover) { | ||
| &:hover { | ||
| background: var(--cpd-color-gray-200); | ||
| } | ||
| } | ||
|
|
||
| &[aria-selected="true"] { | ||
| color: var(--cpd-color-text-primary); | ||
| background: var(--cpd-color-gray-300); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .open { | ||
| display: block; | ||
| } | ||
|
|
||
| .help { | ||
| font: var(--cpd-font-body-sm-regular); | ||
| color: var(--cpd-color-text-secondary); | ||
| } | ||
|
|
||
| .error { | ||
| font: var(--cpd-font-body-sm-medium); | ||
| color: var(--cpd-color-text-critical-primary); | ||
| display: flex; | ||
| gap: var(--cpd-space-2x); | ||
| } | ||
|
|
||
| .error, | ||
| .help { | ||
| margin-block-start: var(--cpd-space-2x); | ||
| } | ||
|
|
||
| &[aria-invalid="true"] { | ||
| label { | ||
| color: var(--cpd-color-text-critical-primary); | ||
| } | ||
|
|
||
| button { | ||
| border-color: var(--cpd-color-text-critical-primary); | ||
| } | ||
| } | ||
| } | ||
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,95 @@ | ||
| /* | ||
| Copyright 2024 New Vector Ltd | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| import { Dropdown } from "./Dropdown"; | ||
| import { fn } from "@storybook/test"; | ||
| import { Meta } from "@storybook/react"; | ||
| import { ComponentProps } from "react"; | ||
|
|
||
| export default { | ||
| title: "Dropdown", | ||
| component: Dropdown, | ||
| tags: ["autodocs"], | ||
| parameters: { | ||
| controls: { | ||
| include: ["defaultValue", "placeholder", "error"], | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| label: { | ||
| type: "string", | ||
| }, | ||
| error: { | ||
| type: "string", | ||
| }, | ||
| placeholder: { | ||
| type: "string", | ||
| }, | ||
| values: { | ||
| type: "string", | ||
| }, | ||
| }, | ||
| args: { | ||
| label: "Label", | ||
| placeholder: "Select an option", | ||
| onValueChange: fn(), | ||
| values: [ | ||
| ["Option1", "Option 1"], | ||
| ["Option2", "Option 2"], | ||
| ], | ||
| }, | ||
| } satisfies Meta<ComponentProps<typeof Dropdown>>; | ||
|
|
||
| export const Default = { | ||
| parameters: { | ||
| design: { | ||
| type: "figma", | ||
| url: "https://www.figma.com/file/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?node-id=799-5732&t=g2Ex9sbzgku1nTIN-4", | ||
| }, | ||
| }, | ||
| }; | ||
| export const WithHelpLabel = { | ||
| args: { | ||
| helpLabel: "Optional help text.", | ||
| }, | ||
| parameters: { | ||
| design: { | ||
| type: "figma", | ||
| url: "https://www.figma.com/file/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?node-id=799-345&t=g2Ex9sbzgku1nTIN-4", | ||
| }, | ||
| }, | ||
| }; | ||
| export const WithError = { | ||
| args: { | ||
| error: "Select an option", | ||
| }, | ||
| parameters: { | ||
| design: { | ||
| type: "figma", | ||
| url: "https://www.figma.com/file/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?node-id=799-370&t=g2Ex9sbzgku1nTIN-4", | ||
| }, | ||
| }, | ||
| }; | ||
| export const WithDefaultValue = { | ||
| args: { | ||
| defaultValue: "Option2", | ||
| }, | ||
| parameters: { | ||
| design: { | ||
| type: "figma", | ||
| url: "https://www.figma.com/file/rTaQE2nIUSLav4Tg3nozq7/Compound-Web-Components?node-id=799-381&t=g2Ex9sbzgku1nTIN-4", | ||
| }, | ||
| }, | ||
| }; |
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.