Skip to content

feat(design-system): add onCloseAutoFocus #1371

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 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-fishes-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': minor
---

feat: add onCloseAutoFocus to Select
4 changes: 3 additions & 1 deletion packages/strapi-design-system/src/Select/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Tag } from '../Tag';
import { Typography } from '../Typography';

type MultiSelectPropsWithoutLabel = Omit<SelectParts.MultiSelectProps, 'value' | 'multi'> &
Pick<SelectParts.ContentProps, 'onCloseAutoFocus'> &
Pick<SelectParts.TriggerProps, 'clearLabel' | 'onClear' | 'size' | 'startIcon' | 'placeholder'> &
Pick<FieldProps, 'hint' | 'id' | 'error'> & {
/**
Expand Down Expand Up @@ -55,6 +56,7 @@ export const MultiSelect = React.forwardRef<HTMLDivElement, MultiSelectProps>(
labelAction,
onChange,
onClear,
onCloseAutoFocus,
onReachEnd,
placeholder,
required,
Expand Down Expand Up @@ -197,7 +199,7 @@ export const MultiSelect = React.forwardRef<HTMLDivElement, MultiSelectProps>(
</SelectParts.Value>
</SelectParts.Trigger>
<SelectParts.Portal>
<SelectParts.Content position="popper" sideOffset={4}>
<SelectParts.Content position="popper" sideOffset={4} onCloseAutoFocus={onCloseAutoFocus}>
<SelectParts.Viewport ref={viewportRef}>
{children}
<Box id={intersectionId} width="100%" height="1px" />
Expand Down
5 changes: 3 additions & 2 deletions packages/strapi-design-system/src/Select/SingleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useIntersection } from '../hooks/useIntersection';
import { Typography } from '../Typography';

type SingleSelectPropsWithoutLabel = Omit<SelectParts.SingleSelectProps, 'value'> &
Pick<SelectParts.ContentProps, 'onCloseAutoFocus'> &
Pick<SelectParts.TriggerProps, 'clearLabel' | 'onClear' | 'size' | 'startIcon' | 'placeholder'> &
Pick<FieldProps, 'error' | 'hint' | 'id'> & {
/**
Expand Down Expand Up @@ -41,7 +42,6 @@ export const SingleSelect = React.forwardRef<SingleSelectInputElement, SingleSel
forwardedRef,
) => {
const generatedId = useId(id);

/**
* Because the trigger needs to be a `div` to allow the clear
* button & tags to be clickable, we need to manually focus it.
Expand Down Expand Up @@ -98,6 +98,7 @@ export const SingleSelectInput = React.forwardRef<SingleSelectInputElement, Sing
label,
onChange,
onClear,
onCloseAutoFocus,
onReachEnd,
placeholder,
required,
Expand Down Expand Up @@ -194,7 +195,7 @@ export const SingleSelectInput = React.forwardRef<SingleSelectInputElement, Sing
</SelectParts.Value>
</SelectParts.Trigger>
<SelectParts.Portal>
<SelectParts.Content position="popper" sideOffset={4}>
<SelectParts.Content position="popper" sideOffset={4} onCloseAutoFocus={onCloseAutoFocus}>
<SelectParts.Viewport ref={viewportRef}>
{children}
<Box id={intersectionId} width="100%" height="1px" />
Expand Down