@@ -4,50 +4,99 @@ import * as stylex from '@stylexjs/stylex';
44import React from 'react' ;
55
66import { Checkmark } from '../../icons/glyphs/checkmark' ;
7+ import { ChevronDown } from '../../icons/glyphs/chevron-down' ;
8+ import { X } from '../../icons/glyphs/x' ;
79import type { ComboboxProps } from '../../primitives/combobox' ;
810import { Combobox as HeadlessCombobox } from '../../primitives/combobox' ;
911import { useRender } from '../../primitives/utils' ;
1012import type { MosaicComponentProps } from '../../props' ;
1113import { mergeStyleProps , themeProps } from '../../props' ;
1214import { reset } from '../../styles/reset.styles' ;
15+ import { Button } from '../button' ;
1316import { Icon } from '../icon' ;
1417import { Input , type InputVariant } from '../input' ;
1518import { useOptionalInputGroupContext } from '../input-group/input-group.context' ;
1619import { scrollAreaRoot , scrollAreaViewport } from '../scroll-area' ;
17- import { styles } from './combobox.styles' ;
20+ import { styles , trigger } from './combobox.styles' ;
1821
1922export type ComboboxRootProps = ComboboxProps ;
2023export type ComboboxSize = 'sm' | 'md' | 'lg' ;
2124export type ComboboxTriggerProps = MosaicComponentProps < 'button' > ;
25+ export type ComboboxClearProps = MosaicComponentProps < 'button' > ;
2226export const ComboboxCollection = HeadlessCombobox . Collection ;
2327
2428const ComboboxAnchorContext = React . createContext < {
2529 anchor : HTMLElement | null ;
2630 setAnchor : React . Dispatch < React . SetStateAction < HTMLElement | null > > ;
2731} | null > ( null ) ;
2832
29- export function ComboboxRoot ( { sideOffset = 8 , ...props } : ComboboxRootProps ) {
33+ export function ComboboxRoot ( { sideOffset = 8 , openOnInputClick = true , ...props } : ComboboxRootProps ) {
3034 const [ anchor , setAnchor ] = React . useState < HTMLElement | null > ( null ) ;
3135 const context = React . useMemo ( ( ) => ( { anchor, setAnchor } ) , [ anchor ] ) ;
3236 return (
3337 < ComboboxAnchorContext . Provider value = { context } >
3438 < HeadlessCombobox . Root
3539 sideOffset = { sideOffset }
40+ openOnInputClick = { openOnInputClick }
3641 { ...props }
3742 />
3843 </ ComboboxAnchorContext . Provider >
3944 ) ;
4045}
4146
4247export const ComboboxTrigger = React . forwardRef < HTMLButtonElement , ComboboxTriggerProps > ( function MosaicComboboxTrigger (
43- { xstyle, ...rest } ,
48+ { xstyle, render , children , ...rest } ,
4449 ref ,
4550) {
4651 return (
4752 < HeadlessCombobox . Trigger
4853 ref = { ref }
54+ render = {
55+ render ??
56+ ( props => (
57+ < Button
58+ xstyle = { trigger . base }
59+ { ...props }
60+ />
61+ ) )
62+ }
4963 { ...mergeStyleProps ( themeProps ( 'combobox-trigger' ) , stylex . props ( xstyle ) , rest ) }
50- />
64+ >
65+ { children ?? (
66+ < Icon
67+ glyph = { ChevronDown }
68+ size = 'md'
69+ />
70+ ) }
71+ </ HeadlessCombobox . Trigger >
72+ ) ;
73+ } ) ;
74+
75+ export const ComboboxClear = React . forwardRef < HTMLButtonElement , ComboboxClearProps > ( function MosaicComboboxClear (
76+ { xstyle, render, children, ...rest } ,
77+ ref ,
78+ ) {
79+ return (
80+ < HeadlessCombobox . Clear
81+ ref = { ref }
82+ render = {
83+ render ??
84+ ( props => (
85+ < Button
86+ xstyle = { [ trigger . base , trigger . clear ] }
87+ { ...props }
88+ />
89+ ) )
90+ }
91+ { ...mergeStyleProps ( themeProps ( 'combobox-clear' ) , stylex . props ( xstyle ) , rest ) }
92+ >
93+ { children ?? (
94+ < Icon
95+ glyph = { X }
96+ size = 'md'
97+ />
98+ ) }
99+ </ HeadlessCombobox . Clear >
51100 ) ;
52101} ) ;
53102
@@ -205,6 +254,7 @@ export const Combobox = {
205254 Collection : ComboboxCollection ,
206255 Input : ComboboxInput ,
207256 Trigger : ComboboxTrigger ,
257+ Clear : ComboboxClear ,
208258 Popup : ComboboxPopup ,
209259 List : ComboboxList ,
210260 Option : ComboboxOption ,
0 commit comments