Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typeahead): use inline style for live element and localize message #4605

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jeremychoisy
Copy link

@jeremychoisy jeremychoisy commented Nov 9, 2023

Use inline style instead of the bootstrap class for the live element to support the usage of the component in the shadow DOM and localize the message itself. Fixes #4560

Before submitting a pull request, please make sure you have at least performed the following:

  • read and followed the CONTRIBUTING.md and DEVELOPER.md guide.
  • built and tested the changes locally.
  • added/updated any applicable tests.
  • added/updated any applicable API documentation.
  • added/updated any applicable demos.

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jeremychoisy,

thanks for the PR.

I think there should be 2 PRs (or at least commits) for this:

  • feat → allow customizing live announcer message (this PR)
  • fix → to fix the shadow DOM issue (separate PR)

I've left a couple of comments in the code as well + the build is failing.

@@ -16,7 +16,7 @@ function getLiveElement(document: any, lazyCreate = false): HTMLElement | null {
element.setAttribute('aria-live', 'polite');
element.setAttribute('aria-atomic', 'true');

element.classList.add('visually-hidden');
element.style.display = 'none';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think there is a reason .visually-hidden and the likes of it exist (ex. .cdk-visually-hidden in material).

I don't think you should use display: none and visiblity: hidden if you want the the content to be read by the screen reader.

You should either inline all the styles necessary, or we should allow providing a Live service at a different level.

WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are 100% right, updated with the inline style taken from Bootstrap visually-hidden, noticed that the cdk-visually-hidden class might be a little more robust, let me know if you'd like to use this one instead.

Regarding inline style VS providing the Live service at a different level, was not really into the service providing based solution because imo it seemed a little bit too complex compared to the inline style one. But seeing the result, I'll give a try to see how it goes because maintaining this inline styling and not benefiting from what could be done on Bootstrap side is kind of sad.

@@ -397,6 +397,18 @@ export class NgbTypeahead implements ControlValueAccessor, OnInit, OnChanges, On
this._nativeElement.value = toString(value);
}

private getAnnounceLocalizedMessage(count: number): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to introduce an @Input() for these kind of translations as well? Will it be useful?

Like @Input() liveAnnouncerMessage: (count: number) => string;

With default being the function you're suggesting I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in this project private methods start with _ → something like _getLiveAnnouncerLocalizedMessage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the @Input, I'm not really sure tbh, I'm not super familiar with the way @angular/localize works but from what I understood, people using this library will generate/maintain translation files based on what is flagged with i18n/$localize. Do we really want/need to provide an additional way to override the translations on top of this already existing mechanism ? Provided keys for this use case seem to cover every possibilities, WDYT ?

@jeremychoisy jeremychoisy force-pushed the fix/use-inline-style-for-live-element-instead-of-b-class branch 2 times, most recently from 02c8b2f to 42c8721 Compare November 10, 2023 14:01
@jeremychoisy jeremychoisy force-pushed the fix/use-inline-style-for-live-element-instead-of-b-class branch 5 times, most recently from 4f9dcc5 to 6429acf Compare January 22, 2024 17:09
Enable the override of the container for the live element, through a DI token,
meaning that the Live service is not provided in root anymore and needs to be
provided when used in a component.
Fixes ng-bootstrap#4560
@jeremychoisy jeremychoisy force-pushed the fix/use-inline-style-for-live-element-instead-of-b-class branch from 6429acf to b5421f3 Compare January 22, 2024 17:12
Enable localization for the live element.
Fixes ng-bootstrap#4560
@jeremychoisy jeremychoisy force-pushed the fix/use-inline-style-for-live-element-instead-of-b-class branch from b5421f3 to 9d94ae0 Compare January 23, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typeahead: Invisible "ngb-live" element is not translatable and may be visible
2 participants