-
Notifications
You must be signed in to change notification settings - Fork 23
[KZN-3415] uses native popover api in SingleSelect #5885
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
Open
Kitty-Al
wants to merge
31
commits into
main
Choose a base branch
from
KZN-3415/popover-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+652
−65
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a985a19
[KZN-3415] uses native popover api in SingleSelect
Kitty-Al c862422
[KZN-3415] fixes lint, ts, failing tests
Kitty-Al 7b4beed
[KZN-3415] adds styling to see a11y behaviour
Kitty-Al 566129a
[KZN-3415] adds tests for the popover
Kitty-Al 6f62ad1
[KZN-3415] fix lint issues
Kitty-Al 401c338
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 5632923
[KZN-3415] adds a note on popover in the docs
Kitty-Al 6f84289
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 6b2cb5b
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 82f8f8e
[KZN-3415] removes classNameOverride
Kitty-Al 2744914
[KZN-3415] change trigger to type
Kitty-Al 11f606b
[KZN-3415] updates positioning logic
Kitty-Al c80d7d1
[KZN-3415] moves interaction tests to storybook
Kitty-Al d32fd52
[KZN-3415] guards against SSR
Kitty-Al c3c8afb
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 428052a
[KZN-3415] improves positioning function performance and handles pare…
Kitty-Al 40cc648
[KZN-3415] removes popover toggle
Kitty-Al 0808407
[KZN-3415] updates popover to handle flicker
Kitty-Al 738f5f1
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 7788311
[KZN-3415] WIP: using css anchor position
Kitty-Al 6f973d3
[KZN-3415] gives the popover a unique id
Kitty-Al d1b90fb
[KZN-3415] refactor the popover positioning
Kitty-Al 06dd126
[KZN-3415] css anchoring position
Kitty-Al dc10e64
[KZN-3415] fixes lint issues
Kitty-Al bf6918a
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al f0ab4e7
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al 239f351
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al e8a2bc6
Merge branch 'main' into KZN-3415/popover-api
Kitty-Al a4e61a7
[KZN-3415] refactoring
Kitty-Al 9841ea8
[KZN-3415] refactors moving out positioning styles
Kitty-Al 24ac24b
[KZN-3415] fixes lint error
Kitty-Al 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
9 changes: 0 additions & 9 deletions
9
packages/components/src/__alpha__/SingleSelect/SingleSelect.module.css
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
packages/components/src/__alpha__/SingleSelect/SingleSelect.spec.tsx
This file was deleted.
Oops, something went wrong.
97 changes: 86 additions & 11 deletions
97
packages/components/src/__alpha__/SingleSelect/SingleSelect.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
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
100 changes: 100 additions & 0 deletions
100
packages/components/src/__alpha__/SingleSelect/_docs/SingleSelect.spec.stories.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,100 @@ | ||
import React from 'react' | ||
import { type Meta, type StoryObj } from '@storybook/react' | ||
import { expect, screen, userEvent, waitFor } from '@storybook/test' | ||
import { SingleSelect } from '../SingleSelect' | ||
import { singleMockItems } from './mockData' | ||
|
||
const meta = { | ||
title: 'Components/SingleSelect/SingleSelect (alpha)', | ||
component: SingleSelect, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
} satisfies Meta<typeof SingleSelect> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
const args = { | ||
items: singleMockItems, | ||
children: ( | ||
<SingleSelect.List> | ||
{singleMockItems.map((item) => ( | ||
<SingleSelect.ListItem key={item.value} id={item.value}> | ||
{item.label} | ||
</SingleSelect.ListItem> | ||
))} | ||
</SingleSelect.List> | ||
), | ||
} | ||
|
||
export const RendersButton: Story = { | ||
args, | ||
play: async () => { | ||
expect(screen.getByRole('button')).toBeInTheDocument() | ||
}, | ||
} | ||
|
||
export const OpensPopoverOnClick: Story = { | ||
args, | ||
play: async () => { | ||
const trigger = screen.getByRole('button') | ||
await userEvent.click(trigger) | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true')) | ||
const options = await screen.findAllByRole('option') | ||
expect(options[0]).toBeVisible() | ||
expect(options[0]).toHaveTextContent(singleMockItems[0].label) | ||
}, | ||
} | ||
|
||
export const ClosesPopoverOnSelect: Story = { | ||
args, | ||
play: async () => { | ||
const trigger = screen.getByRole('button') | ||
await userEvent.click(trigger) | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true')) | ||
const options = await screen.findAllByRole('option') | ||
await userEvent.click(options[0]) | ||
await waitFor(() => expect(screen.queryAllByRole('option')).toHaveLength(0)) | ||
}, | ||
} | ||
|
||
export const KeyboardNavigation: Story = { | ||
args, | ||
play: async () => { | ||
const trigger = screen.getByRole('button') | ||
trigger.focus() | ||
await userEvent.keyboard('{Enter}') | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true')) | ||
const options = await screen.findAllByRole('option') | ||
await userEvent.keyboard('{ArrowDown}') | ||
expect(options[1]).toHaveAttribute('data-focused', 'true') | ||
await userEvent.keyboard('{ArrowUp}') | ||
expect(options[0]).toHaveAttribute('data-focused', 'true') | ||
}, | ||
} | ||
|
||
export const KeyboardSelectsItem: Story = { | ||
args, | ||
play: async () => { | ||
const trigger = screen.getByRole('button') | ||
trigger.focus() | ||
await userEvent.keyboard('{Enter}') | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true')) | ||
await userEvent.keyboard('{ArrowDown}') | ||
await userEvent.keyboard('{Enter}') | ||
await waitFor(() => expect(screen.queryAllByRole('option')).toHaveLength(0)) | ||
}, | ||
} | ||
|
||
export const KeyboardEscapeClosesPopover: Story = { | ||
args, | ||
play: async () => { | ||
const trigger = screen.getByRole('button') | ||
await userEvent.click(trigger) | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'true')) | ||
await userEvent.keyboard('{Escape}') | ||
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'false')) | ||
}, | ||
} |
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
23 changes: 21 additions & 2 deletions
23
packages/components/src/__alpha__/SingleSelect/_docs/SingleSelect.stories.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
21 changes: 21 additions & 0 deletions
21
packages/components/src/__alpha__/SingleSelect/context/SingleSelectContext.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,21 @@ | ||
import { createContext, useContext } from 'react' | ||
import { type Key } from '@react-types/shared' | ||
import { type SelectItem, type SelectSection } from '../types' | ||
|
||
type SingleSelectContextType = { | ||
isOpen: boolean | ||
setOpen: (open: boolean) => void | ||
selectedKey: Key | null | ||
items: (SelectItem | SelectSection)[] | ||
anchorName: string | ||
} | ||
|
||
export const SingleSelectContext = createContext<SingleSelectContextType | undefined>(undefined) | ||
|
||
export const useSingleSelectContext = (): SingleSelectContextType => { | ||
const context = useContext(SingleSelectContext) | ||
if (!context) { | ||
throw new Error('useSingleSelectContext must be used within a SingleSelectContext.Provider') | ||
} | ||
return context | ||
} |
1 change: 1 addition & 0 deletions
1
packages/components/src/__alpha__/SingleSelect/context/index.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 @@ | ||
export * from './SingleSelectContext' |
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 |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
.list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--spacing-16); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
packages/components/src/__alpha__/SingleSelect/subcomponents/List/List.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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trigger at the moment is controlled entirely by our implementation with only the buttonRef exposed. Have we considered any potential needs for our consumers to either have a custom trigger or to be able to pass in data attributes that they may used in testing or for programmatically shifting focus?
The main thing that gets me thinking about that is this recent support question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the callout. I totally appreciate that our users might need more flexibility here. I've written a ticket so that we capture the work on exposing the trigger & popover, trying to give our users as much flexibility as possible https://cultureamp.atlassian.net/browse/KZN-3462