@@ -17,6 +17,7 @@ import type { MonthsProps } from "./components/Months";
1717import { DayPicker } from "./DayPicker" ;
1818import { labelMonthDropdown , labelYearDropdown } from "./labels/index.js" ;
1919import { ja } from "./locale/ja.js" ;
20+ import { UI } from "./UI" ;
2021
2122const testId = "test" ;
2223const dayPicker = ( ) => screen . getByTestId ( testId ) ;
@@ -49,6 +50,99 @@ test("apply classnames and style according to props", () => {
4950 expect ( dayPicker ( ) ) . toHaveStyle ( { color : "rgb(255, 0, 0)" } ) ;
5051} ) ;
5152
53+ describe ( "when rendering custom inline styles for component slots" , ( ) => {
54+ beforeEach ( ( ) => {
55+ render (
56+ < DayPicker
57+ data-testid = { testId }
58+ styles = { {
59+ [ UI . CaptionLabel ] : { color : "purple" } ,
60+ [ UI . Chevron ] : { fill : "red" } ,
61+ [ UI . NextMonthButton ] : { backgroundColor : "green" } ,
62+ [ UI . PreviousMonthButton ] : { backgroundColor : "blue" } ,
63+ } }
64+ /> ,
65+ ) ;
66+ } ) ;
67+
68+ test ( "applies the previous button style" , ( ) => {
69+ expect ( previousButton ( ) ) . toHaveAttribute (
70+ "style" ,
71+ "background-color: blue;" ,
72+ ) ;
73+ } ) ;
74+
75+ test ( "applies the next button style" , ( ) => {
76+ expect ( nextButton ( ) ) . toHaveAttribute ( "style" , "background-color: green;" ) ;
77+ } ) ;
78+
79+ test ( "applies the chevron style" , ( ) => {
80+ expect ( document . querySelector ( ".rdp-chevron" ) ) . toHaveAttribute (
81+ "style" ,
82+ "fill: red;" ,
83+ ) ;
84+ } ) ;
85+
86+ test ( "applies the caption label style" , ( ) => {
87+ expect ( document . querySelector ( ".rdp-caption_label" ) ) . toHaveAttribute (
88+ "style" ,
89+ "color: purple;" ,
90+ ) ;
91+ } ) ;
92+ } ) ;
93+
94+ describe ( "when rendering custom inline styles for dropdown slots" , ( ) => {
95+ beforeEach ( ( ) => {
96+ render (
97+ < DayPicker
98+ captionLayout = "dropdown"
99+ endMonth = { new Date ( 2025 , 11 ) }
100+ month = { new Date ( 2024 , 0 ) }
101+ startMonth = { new Date ( 2024 , 0 ) }
102+ styles = { {
103+ [ UI . CaptionLabel ] : { color : "purple" } ,
104+ [ UI . Chevron ] : { fill : "red" } ,
105+ [ UI . Dropdown ] : { backgroundColor : "yellow" } ,
106+ [ UI . DropdownRoot ] : { borderColor : "blue" } ,
107+ [ UI . MonthsDropdown ] : { color : "green" } ,
108+ [ UI . YearsDropdown ] : { fontWeight : 700 } ,
109+ } }
110+ /> ,
111+ ) ;
112+ } ) ;
113+
114+ test ( "applies the dropdown root style" , ( ) => {
115+ expect (
116+ screen . getByRole ( "combobox" , { name : labelMonthDropdown ( ) } )
117+ . parentElement ,
118+ ) . toHaveAttribute ( "style" , "border-color: blue;" ) ;
119+ } ) ;
120+
121+ test ( "applies the month dropdown style with the base dropdown style" , ( ) => {
122+ expect (
123+ screen . getByRole ( "combobox" , { name : labelMonthDropdown ( ) } ) ,
124+ ) . toHaveAttribute ( "style" , "background-color: yellow; color: green;" ) ;
125+ } ) ;
126+
127+ test ( "applies the year dropdown style with the base dropdown style" , ( ) => {
128+ expect (
129+ screen . getByRole ( "combobox" , { name : labelYearDropdown ( ) } ) ,
130+ ) . toHaveAttribute ( "style" , "background-color: yellow; font-weight: 700;" ) ;
131+ } ) ;
132+
133+ test ( "applies the dropdown caption label style" , ( ) => {
134+ expect (
135+ document . querySelector ( ".rdp-dropdown_root .rdp-caption_label" ) ,
136+ ) . toHaveAttribute ( "style" , "color: purple;" ) ;
137+ } ) ;
138+
139+ test ( "applies the dropdown chevron style" , ( ) => {
140+ expect (
141+ document . querySelector ( ".rdp-dropdown_root .rdp-chevron" ) ,
142+ ) . toHaveAttribute ( "style" , "fill: red;" ) ;
143+ } ) ;
144+ } ) ;
145+
52146test ( "forward aria attributes to the root element" , ( ) => {
53147 render (
54148 < DayPicker
0 commit comments