components icon indicating copy to clipboard operation
components copied to clipboard

bug(Datepicker): Hidden calendar button not in the selected language

Open JaDub3 opened this issue 2 years ago • 11 comments

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

Description

When the locale changes for the datepicker, the calendar switch to the appropriate language. But the hidden 'Close calendar' button stay in english. This is an issue for accessibility, especially for reader application.

image

Reproduction

Steps to reproduce:

  1. Change locale to French
  2. Open the Datepicker
  3. Press 'TAB' until the hidden button appear

Expected Behavior

The label and content of the button should be in the language specified by the locale.

Actual Behavior

The hidden button stay in english

Environment

  • Angular: 11+
  • CDK/Material: Datepicker
  • Browser(s): Chrome, Firefox
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

JaDub3 avatar Jun 03 '22 16:06 JaDub3

Since the Close calendar string comes from the MatDatepickerIntl and is not hard-coded, this seems to be an issue with the demo, rather than the date picker itself.

zarend avatar Jun 10 '22 16:06 zarend

How can we change it then? I showed a screenshot of the demo in the ticket, but I have the same issue in my code.

Le 10 juin 2022 à 12:52, Zach Arend @.***> a écrit :

 Since the Close calendar string comes from the MatDatepickerIntl and is not hard-coded, this seems to be an issue with the demo, rather than the date picker itself.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

JaDub3 avatar Jun 10 '22 17:06 JaDub3

This demo needs to implement proving a different value for MatDatepickerIntl because that is where the "Close calendar" string comes from. Here are roughly the steps that need to happen to implement this in the demo.

  1. extend MatDatepickerIntl with French strings
class MatDatepickerIntlFr extends MatDatepickerIntl {
   closeCalendar: "
Fermer le calendrier"
  // ...
}
  1. Inject MatDatepickerIntl into the example.
  2. When clicking "Dynamically switch to French", inject MatDatepickerIntlFr instead

Community contributions are welcome :).

If your code only needs french and doesn't need English, you can provide MatDatepickerIntlFr in your code. there would be no need to change it dynmically. The code would look something like:

provide: MatDatepickerIntl, useClass: MatDatepickerIntlFr

zarend avatar Jun 17 '22 17:06 zarend

Thank you for your answer. I’m not to sure how you can change the injected value on the click event, but I got the general.

For now, I solved my issue by providing a factory for the overided class who subscribe on a language change event to switch label.

But I must admit, I’m curious about the ‘When clicking "Dynamically switch to French", inject MatDatepickerIntlFrinstead’? How do you change the injector dynamically? I did not see any function to do so within the DateAdapter?

Le 17 juin 2022 à 13:21, Zach Arend @.***> a écrit :

 This demo needs to implement proving a different value for MatDatepickerIntl because that is where the "Close calendar" string comes from. Here are roughly the steps that need to happen to implement this in the demo.

extend MatDatepickerIntl with French strings class MatDatepickerIntlFr extends MatDatepickerIntl { closeCalendar: " Fermer le calendrier" // ... } Inject MatDatepickerIntl into the example. When clicking "Dynamically switch to French", inject MatDatepickerIntlFr instead Community contributions are welcome :).

If your code only needs french and doesn't need English, you can provide MatDatepickerIntlFr in your code. there would be no need to change it dynmically. The code would look something like:

provide: MatDatepickerIntl, useClass: MatDatepickerIntlFr — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

JaDub3 avatar Jun 17 '22 21:06 JaDub3

I believe this should be doable with a factory provider. Provide the locale as a dependency to the factory provider. The factory returns an instance of either MatDatepickerIntl or MatDatepickerIntlFr depending on what the locale is.

zarend avatar Jun 17 '22 23:06 zarend

I will try solve.

maykonpacheco avatar Jul 28 '22 20:07 maykonpacheco

Hey @maykonpacheco, are you still working on that issue?

GKosheev avatar Aug 13 '22 02:08 GKosheev

@GKosheev yes, do you have any suggestion?

maykonpacheco avatar Aug 15 '22 18:08 maykonpacheco

Talked though this with @amysorto , will be improving the example.

AncelHernandez avatar Sep 02 '22 02:09 AncelHernandez

Just an update on this, seems like there needs to be changes done on the to the datepicker-base.ts file. When locale updates happen, the class does not re-evaluate the value of the close calendar button. I think moving the initialization of the _closeButtonText value from the constructor to ngOnInit would solve this issue since it would reevaluate every time the calendar content is rendered. But maybe we could listen in to the intl.changes observable and evaluate those values when that emits.

AncelHernandez avatar Sep 02 '22 19:09 AncelHernandez

You can do intl.changes.next() after changing the value of the close button text so that the service knows something needs to be updated (MatDatepickerIntl docs).

amysorto avatar Sep 02 '22 23:09 amysorto

Is this issue still open? I would like to work on this.

Gua00va avatar Feb 15 '23 19:02 Gua00va

Hello @Gua00va ,

I believe this issue is still open, and you are welcome to work on it.

-Zach

zarend avatar Feb 16 '23 15:02 zarend

I believe this issue is still open, and you are welcome to work on it.

Aadi1605 avatar Mar 09 '23 07:03 Aadi1605

i want to work on this issues please assign me issue

piyushsrvastava avatar Mar 18 '23 05:03 piyushsrvastava

function setCloseButtonLocale(locale) { const closeButton = document.querySelector('.close-button');

switch (locale) { case 'en-US': closeButton.innerText = 'Close calendar'; break; case 'fr-FR': closeButton.innerText = 'Fermer le calendrier'; break; // add additional cases for other supported locales default: closeButton.innerText = 'Close calendar'; } } you are using this code

piyushsrvastava avatar Mar 18 '23 05:03 piyushsrvastava

@piyushsrvastava, I wanted to bring to your attention that a pull request has already been submitted. #26738

hamzajazyri avatar Mar 18 '23 06:03 hamzajazyri

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.