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

feat: introduce more customizable skip-nav #208

Merged
merged 2 commits into from
Jan 30, 2024
Merged

Conversation

dlockhart
Copy link
Contributor

A case recently came up where a more customizable skip-nav link was required. Both the text needed to be customized as well as the focus logic when activated.

To solve this, I've renamed the existing d2l-navigation-skip component to d2l-navigation-skip-main to reflect its "skip to main content" text and "focus on the

element" functionality. That leaves d2l-navigation-skip available to become a more customizable version. d2l-navigation-skip was only ever used internally to this repo, so no migration is required.

@dlockhart dlockhart requested a review from a team as a code owner January 29, 2024 18:11

class NavigationSkipMain extends FocusMixin(LocalizeNavigationElement(LitElement)) {

static get focusElementSelector() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I was at it, I made both of these FocuxMixin-enabled, so calling focus() on the component will delegate it to the underlying <a>.

return html`<d2l-navigation-skip text="${this.localize('skipNav')}" @click="${this._handleSkipNav}" class="vdiff-target"></d2l-navigation-skip>`;
}

_handleSkipNav() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just the existing logic moved here.


static get styles() {
return css`
a {
left: -10000px;
inset-inline-start: -10000px;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removes the need for RtlMixin.

render() {
return html`<a tabindex="0" @click="${this._handleSkipNav}" @keydown="${this._handleKeyDown}">${this.localize('skipNav')}</a>`;
return html`<a tabindex="0" @keydown="${this._handleKeyDown}" class="vdiff-target">${this.text}</a>`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the mouse click event just bubbles up as if it originated from this component and pressing ENTER also fires that event.


});

describe('skip logic', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There wasn't anything testing this logic before, so I added it.


describe('d2l-navigation-skip-main', () => {

['en', 'ar'].forEach(lang => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just testing Arabic here to exercise the RTL logic.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's worth adding tests that check the focus does go where we expect? It seems like the unit tests cover these pretty well, maybe just one of those cases where either unit or vdiff would work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d2l-navigation-skip doesn't have any focus logic, it just fires the event. But yeah, d2l-navigation-skip-main's unit tests cover all its focus logic, and I did originally have that in the vdiff but since it was testable from a unit test I opted to do it there to speed things up.

}

render() {
return html`<d2l-navigation-skip text="${this.localize('skipNav')}" @click="${this._handleSkipNav}" class="vdiff-target"></d2l-navigation-skip>`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Love seeing the vdiff-target stuff just work!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know! I had to refer to the docs to make sure I did it right, which also just worked. 🎉

@dlockhart dlockhart merged commit 4bc4801 into main Jan 30, 2024
3 checks passed
@dlockhart dlockhart deleted the GAUD-5025/custom-skip-nav branch January 30, 2024 17:30
Copy link

🎉 This PR is included in version 5.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants