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(breadcrumbs): trigger change event on breadcrumbs via keyboard #4769

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/breadcrumbs/src/BreadcrumbItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export class BreadcrumbItem extends LikeAnchor(Focusable) {
return html`
<a
id="item-link"
href=${ifDefined(!this.isLastOfType ? this.href : undefined)}
href=${ifDefined(
!this.isLastOfType ? this.href || '#' : undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this lead to a jump to the top of the page when "#" is set?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! I have updated the changes. Let' see if we can land this for tomorrow's release.

)}
tabindex=${0}
aria-current=${ifDefined(
this.isLastOfType ? 'page' : undefined
Expand Down
28 changes: 28 additions & 0 deletions packages/breadcrumbs/test/breadcrumbs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { testForLitDevWarnings } from '../../../test/testing-helpers.js';

import '@spectrum-web-components/breadcrumbs/sp-breadcrumbs.js';
import '@spectrum-web-components/breadcrumbs/sp-breadcrumb-item.js';
import { sendKeys } from '@web/test-runner-commands';

describe('Breadcrumbs', () => {
testForLitDevWarnings(
Expand Down Expand Up @@ -166,4 +167,31 @@ describe('Breadcrumbs', () => {
expect(changeSpy).to.have.been.calledOnce;
expect(changeSpy).to.have.been.calledWith('0');
});

it('should emit a change event on Enter keypress', async () => {
const changeSpy = spy();

const el = await fixture<Breadcrumbs>(html`
<sp-breadcrumbs
@change=${(
event: Event & { detail: BreadcrumbSelectDetail }
) => {
changeSpy(event.detail.value);
}}
>
${getBreadcrumbs(4)}
</sp-breadcrumbs>
`);

await elementUpdated(el);

// Simulate a click from the visible breadcrumb.
const breadcrumbs = el.querySelectorAll('sp-breadcrumb-item');

breadcrumbs[1].focus();
await sendKeys({ press: 'Enter' });

expect(changeSpy).to.have.been.calledOnce;
expect(changeSpy).to.have.been.calledWith('1');
});
});
Loading