Skip to content

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.

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.

this._nativeElement.value = toString(value);
}

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

@maxokorokov maxokorokov Nov 10, 2023

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 7 times, most recently from b5421f3 to 9d94ae0 Compare January 23, 2024 08:58
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 9d94ae0 to f33f92d Compare February 19, 2025 15:57
@jeremychoisy jeremychoisy force-pushed the fix/use-inline-style-for-live-element-instead-of-b-class branch from f33f92d to 68d53eb Compare March 7, 2025 00:30
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 68d53eb to 18753e5 Compare March 7, 2025 00:52
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