Skip to content
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

feat: combobox onclose state can be tracked #2396

Merged
merged 1 commit into from
Sep 26, 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
23 changes: 22 additions & 1 deletion next-docs/pages/components/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactNode } from 'react';
import Preview from '../../components/codePreview/Preview';
import ComponentAnatomy from '../../components/ComponentAnatomy';
import ComponentPageDescription from '../../components/ComponentPageDescription';
import type { ComponentNames } from '../../components/getComponent';
import Layout from '../../components/Layout';
import PropsTable from '../../components/PropsTable';
import Default from '../../public/examples/combobox/Default';
Expand All @@ -12,7 +13,6 @@ import MultiSelect from '../../public/examples/combobox/MultiSelect';
import Select from '../../public/examples/combobox/Select';
import SelectStates from '../../public/examples/combobox/SelectStates';
import useComponent from '../../utils/useComponent';
import type { ComponentNames } from '../../components/getComponent';

const COMPONENT_NAME: ComponentNames = 'Combobox';

Expand Down Expand Up @@ -242,6 +242,13 @@ const PageCombobox = () => {
default: '-',
description: 'Tailwind classes for custom styles.',
},
{
name: 'onClose',
type: '(value: unknown) => void;',
required: false,
default: '-',
description: 'Called when the Combobox is dismissed.',
},
]}
/>

Expand Down Expand Up @@ -457,6 +464,13 @@ const PageCombobox = () => {
default: '-',
description: 'Whether or not the Listbox is open.',
},
{
name: 'onClose',
type: '(value: unknown) => void;',
required: false,
default: '-',
description: 'Called when the Combobox is dismissed.',
},
]}
/>

Expand Down Expand Up @@ -527,6 +541,13 @@ const PageCombobox = () => {
default: '-',
description: 'Whether or not the Listbox is open.',
},
{
name: 'onClose',
type: '(value: unknown) => void;',
required: false,
default: '-',
description: 'Called when the Combobox is dismissed.',
},
]}
/>

Expand Down
4 changes: 2 additions & 2 deletions next-docs/public/examples/combobox/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Example = () => {
>
{({ open }) => (
<>
<Combobox.Trigger open={open} className="min-w-[18.75rem]">
<Combobox.Trigger open={open} className="min-w-[18.75rem]" onClose={console.log}>
<Combobox.Input
open={open}
placeholder={'Choose a name...'}
Expand Down Expand Up @@ -90,7 +90,7 @@ const Example = () => {
>
{({ open }) => (
<>
<Combobox.Trigger open={open} className="min-w-[18.75rem]">
<Combobox.Trigger open={open} className="min-w-[18.75rem]" onClose={console.log}>
<Combobox.Input
open={open}
placeholder={'Choose a name...'}
Expand Down
3 changes: 3 additions & 0 deletions next-docs/public/examples/combobox/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const Example = () => {
counter={selected0.length}
placeholder="Choose an option"
displayValue={({ label }) => label}
onClose={console.log}
>
<ControlsChevronDownSmall />
</Combobox.MultiSelect>
Expand Down Expand Up @@ -101,6 +102,7 @@ const Example = () => {
counter={selected1.length}
placeholder="Choose an option"
displayValue={({ label }) => label}
onClose={console.log}
>
<ControlsChevronDownSmall />
</Combobox.MultiSelect>
Expand Down Expand Up @@ -146,6 +148,7 @@ const Example = () => {
counter={selected2.length}
placeholder="Choose an option"
displayValue={({ label }) => label}
onClose={console.log}
>
<ControlsChevronDownSmall />
</Combobox.MultiSelect>
Expand Down
45 changes: 24 additions & 21 deletions packages/assets/src/icons/IconLivespins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ const Svg = (props: React.SVGProps<SVGSVGElement>) => (
</svg>
);
type IconProps = {
backgroundColor?: ColorProps;
circleColor?: ColorProps;
color?: ColorProps;
backgroundColor?: ColorProps,
circleColor?: ColorProps,
color?: ColorProps,
};
const IconLivespins = styled(Svg).withConfig({
shouldForwardProp: (prop) =>
!['backgroundColor', 'circleColor', 'color'].includes(prop),
})<IconProps>(({ backgroundColor, circleColor, color, theme }) => [
backgroundColor && {
backgroundColor: themed('color', backgroundColor)(theme),
padding: backgroundColor ? '0.25em' : 0,
overflow: 'visible',
borderRadius: '50%',
},
color && {
color: themed('color', color)(theme),
},
circleColor && {
circle: {
fill: themed('color', circleColor)(theme),
const IconLivespins =
styled(Svg).withConfig({
shouldForwardProp: prop =>
!['backgroundColor', 'circleColor', 'color'].includes(prop),
}) <
IconProps >
(({ backgroundColor, circleColor, color, theme }) => [
backgroundColor && {
backgroundColor: themed('color', backgroundColor)(theme),
padding: backgroundColor ? '0.25em' : 0,
overflow: 'visible',
borderRadius: '50%',
},
},
]);
color && {
color: themed('color', color)(theme),
},
circleColor && {
circle: {
fill: themed('color', circleColor)(theme),
},
},
]);
export default IconLivespins;
12 changes: 10 additions & 2 deletions workspaces/core/src/combobox/Combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef } from 'react';
import React, { forwardRef, useEffect, useState } from 'react';
import {
Combobox as HeadlessCombobox,
Transition as HeadlessTransition,
Expand Down Expand Up @@ -109,12 +109,20 @@ const Trigger = forwardRef<HTMLDivElement, WithChildren<SelectProps>>(({
children,
className,
innerLabel,
open,
onClose,
},
ref
) => {
const { size, input, popper, disabled, isError } =
const { value, size, input, popper, disabled, isError } =
useComboboxContext('Combobox.Trigger');

useEffect(() => {
if (!open && typeof onClose === 'function') {
onClose(value)
}
}, [open, value]);

return (
<div
tabIndex={-1}
Expand Down
3 changes: 2 additions & 1 deletion workspaces/core/src/combobox/private/types/SelectProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ type SelectProps = {
label?: JSX.Element | string;
placeholder?: JSX.Element | string;
open?: boolean;
value?: undefined;
value?: unknown;
innerLabel?: boolean;
className?: string;
multiple?: boolean;
counter?: number;
onClose?: (value: unknown) => void;
};

export default SelectProps
Loading