File tree Expand file tree Collapse file tree
packages/components/src/components/DatePicker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,4 +65,27 @@ describe('DatePicker', () => {
6565
6666 expect ( getRoot ( ) ) . toHaveTextContent ( 'fail' ) ;
6767 } ) ;
68+
69+ it ( 'should allow custom open button icon via triggerButton slot' , ( ) => {
70+ render (
71+ < DatePicker
72+ { ...baseProps }
73+ slotProps = { {
74+ triggerButton : {
75+ children : < span data-testid = "custom-open-icon" /> ,
76+ } ,
77+ } }
78+ />
79+ ) ;
80+
81+ const openButton = screen . getByRole ( 'button' ) ;
82+
83+ expect ( screen . getByTestId ( 'custom-open-icon' ) ) . toBeInTheDocument ( ) ;
84+
85+ expect (
86+ openButton . querySelector ( '[data-testid="custom-open-icon"]' )
87+ ) . toBeInTheDocument ( ) ;
88+
89+ expect ( openButton . querySelector ( 'svg' ) ) . not . toBeInTheDocument ( ) ;
90+ } ) ;
6891} ) ;
Original file line number Diff line number Diff line change @@ -79,23 +79,31 @@ export function DatePickerRender<T extends DateValue>(
7979 // eslint-disable-next-line no-unsafe-optional-chaining
8080 const { slotProps : rootSlotProps , ...otherRoot } = slotProps ?. root || { } ;
8181
82+ const triggerButtonProps = mergeProps (
83+ {
84+ variant : isInvalid ? 'error' : 'fade-contrast' ,
85+ className : s . calendar ,
86+ children : < IconCalendarO16 /> ,
87+ } ,
88+ buttonProps ,
89+ slotProps ?. triggerButton
90+ ) ;
91+
8292 const mergedRootSlotProps = {
8393 ...rootSlotProps ,
84- group : mergeProps ( rootSlotProps ?. group , groupProps , {
85- ref : anchorRef ,
86- endAddon : (
87- < >
88- { endAddon }
89- < IconButton
90- variant = { isInvalid ? 'error' : 'fade-contrast' }
91- className = { s . calendar }
92- { ...buttonProps }
93- >
94- < IconCalendarO16 />
95- </ IconButton >
96- </ >
97- ) ,
98- } ) ,
94+ group : mergeProps (
95+ groupProps ,
96+ {
97+ ref : anchorRef ,
98+ endAddon : (
99+ < >
100+ { endAddon }
101+ < IconButton { ...triggerButtonProps } />
102+ </ >
103+ ) ,
104+ } ,
105+ rootSlotProps ?. group
106+ ) ,
99107 } ;
100108
101109 const rootProps = mergeProps (
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type {
1010 DateInputRef ,
1111} from '../DateInput' ;
1212import type { FormFieldLabelProps } from '../FormField' ;
13+ import type { IconButtonProps } from '../IconButton' ;
1314import type { PopoverProps } from '../Popover' ;
1415
1516export type DatePickerProps < T extends DateValue > = {
@@ -48,6 +49,7 @@ export type DatePickerProps<T extends DateValue> = {
4849 label ?: FormFieldLabelProps ;
4950 popover ?: PopoverProps ;
5051 calendar ?: CalendarProps < T > ;
52+ triggerButton ?: IconButtonProps ;
5153 } ;
5254} & Omit < AriaDatePickerProps < T > , 'description' | 'validationState' > ;
5355
You can’t perform that action at this time.
0 commit comments