@@ -4273,6 +4273,129 @@ describe("DatePicker", () => {
42734273 } ) ;
42744274 } ) ;
42754275
4276+ describe ( "aria attributes on input" , ( ) => {
4277+ it ( "should pass aria-describedby to the input using standard HTML attribute name" , ( ) => {
4278+ const { container } = render (
4279+ < DatePicker selected = { newDate ( ) } aria-describedby = "description-id" /> ,
4280+ ) ;
4281+ const input = safeQuerySelector ( container , "input" ) ;
4282+ expect ( input . getAttribute ( "aria-describedby" ) ) . toBe ( "description-id" ) ;
4283+ } ) ;
4284+
4285+ it ( "should pass aria-describedby to the input using camelCase prop name" , ( ) => {
4286+ const { container } = render (
4287+ < DatePicker selected = { newDate ( ) } ariaDescribedBy = "description-id" /> ,
4288+ ) ;
4289+ const input = safeQuerySelector ( container , "input" ) ;
4290+ expect ( input . getAttribute ( "aria-describedby" ) ) . toBe ( "description-id" ) ;
4291+ } ) ;
4292+
4293+ it ( "should prefer standard HTML attribute name over camelCase for aria-describedby" , ( ) => {
4294+ const { container } = render (
4295+ < DatePicker
4296+ selected = { newDate ( ) }
4297+ aria-describedby = "standard-id"
4298+ ariaDescribedBy = "camelcase-id"
4299+ /> ,
4300+ ) ;
4301+ const input = safeQuerySelector ( container , "input" ) ;
4302+ expect ( input . getAttribute ( "aria-describedby" ) ) . toBe ( "standard-id" ) ;
4303+ } ) ;
4304+
4305+ it ( "should pass aria-invalid to the input using standard HTML attribute name" , ( ) => {
4306+ const { container } = render (
4307+ < DatePicker selected = { newDate ( ) } aria-invalid = "true" /> ,
4308+ ) ;
4309+ const input = safeQuerySelector ( container , "input" ) ;
4310+ expect ( input . getAttribute ( "aria-invalid" ) ) . toBe ( "true" ) ;
4311+ } ) ;
4312+
4313+ it ( "should pass aria-invalid to the input using camelCase prop name" , ( ) => {
4314+ const { container } = render (
4315+ < DatePicker selected = { newDate ( ) } ariaInvalid = "true" /> ,
4316+ ) ;
4317+ const input = safeQuerySelector ( container , "input" ) ;
4318+ expect ( input . getAttribute ( "aria-invalid" ) ) . toBe ( "true" ) ;
4319+ } ) ;
4320+
4321+ it ( "should pass aria-labelledby to the input using standard HTML attribute name" , ( ) => {
4322+ const { container } = render (
4323+ < DatePicker selected = { newDate ( ) } aria-labelledby = "label-id" /> ,
4324+ ) ;
4325+ const input = safeQuerySelector ( container , "input" ) ;
4326+ expect ( input . getAttribute ( "aria-labelledby" ) ) . toBe ( "label-id" ) ;
4327+ } ) ;
4328+
4329+ it ( "should pass aria-labelledby to the input using camelCase prop name" , ( ) => {
4330+ const { container } = render (
4331+ < DatePicker selected = { newDate ( ) } ariaLabelledBy = "label-id" /> ,
4332+ ) ;
4333+ const input = safeQuerySelector ( container , "input" ) ;
4334+ expect ( input . getAttribute ( "aria-labelledby" ) ) . toBe ( "label-id" ) ;
4335+ } ) ;
4336+
4337+ it ( "should pass aria-required to the input using standard HTML attribute name" , ( ) => {
4338+ const { container } = render (
4339+ < DatePicker selected = { newDate ( ) } aria-required = "true" /> ,
4340+ ) ;
4341+ const input = safeQuerySelector ( container , "input" ) ;
4342+ expect ( input . getAttribute ( "aria-required" ) ) . toBe ( "true" ) ;
4343+ } ) ;
4344+
4345+ it ( "should pass aria-required to the input using camelCase prop name" , ( ) => {
4346+ const { container } = render (
4347+ < DatePicker selected = { newDate ( ) } ariaRequired = "true" /> ,
4348+ ) ;
4349+ const input = safeQuerySelector ( container , "input" ) ;
4350+ expect ( input . getAttribute ( "aria-required" ) ) . toBe ( "true" ) ;
4351+ } ) ;
4352+
4353+ it ( "should pass aria attributes to custom input using standard HTML attribute names" , ( ) => {
4354+ const { container } = render (
4355+ < DatePicker
4356+ selected = { newDate ( ) }
4357+ customInput = { < CustomInput /> }
4358+ aria-describedby = "desc-id"
4359+ aria-invalid = "true"
4360+ aria-labelledby = "label-id"
4361+ aria-required = "true"
4362+ /> ,
4363+ ) ;
4364+ const input = safeQuerySelector ( container , "input" ) ;
4365+ expect ( input . getAttribute ( "aria-describedby" ) ) . toBe ( "desc-id" ) ;
4366+ expect ( input . getAttribute ( "aria-invalid" ) ) . toBe ( "true" ) ;
4367+ expect ( input . getAttribute ( "aria-labelledby" ) ) . toBe ( "label-id" ) ;
4368+ expect ( input . getAttribute ( "aria-required" ) ) . toBe ( "true" ) ;
4369+ } ) ;
4370+
4371+ it ( "should preserve custom input's own aria attributes when DatePicker does not specify them" , ( ) => {
4372+ // Custom input with its own aria attributes
4373+ const CustomInputWithAria = React . forwardRef <
4374+ HTMLInputElement ,
4375+ React . InputHTMLAttributes < HTMLInputElement >
4376+ > ( ( props , ref ) => (
4377+ < input
4378+ ref = { ref }
4379+ { ...props }
4380+ aria-describedby = "custom-desc"
4381+ aria-invalid = "false"
4382+ />
4383+ ) ) ;
4384+ CustomInputWithAria . displayName = "CustomInputWithAria" ;
4385+
4386+ const { container } = render (
4387+ < DatePicker
4388+ selected = { newDate ( ) }
4389+ customInput = { < CustomInputWithAria /> }
4390+ /> ,
4391+ ) ;
4392+ const input = safeQuerySelector ( container , "input" ) ;
4393+ // Should preserve the custom input's aria attributes since DatePicker didn't specify any
4394+ expect ( input . getAttribute ( "aria-describedby" ) ) . toBe ( "custom-desc" ) ;
4395+ expect ( input . getAttribute ( "aria-invalid" ) ) . toBe ( "false" ) ;
4396+ } ) ;
4397+ } ) ;
4398+
42764399 it ( "should not customize the className attribute if showIcon is set to false" , ( ) => {
42774400 const { container } = render (
42784401 < DatePicker selected = { newDate ( "2021-04-15" ) } /> ,
0 commit comments