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: scrolling to the first item #1753

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions e2e/integration/menu.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ describe('Menu', () => {
.should('be.visible');
});

it('should sync active menu items while scroll back and scroll again', () => {
cy.contains('h2', 'Add a new pet to the store')
.scrollIntoView()
.wait(100)
.get('[role=menuitem].active')
.children()
.last()
.should('have.text', 'Add a new pet to the store')
.should('be.visible');

cy.contains('h1', 'Swagger Petstore')
.scrollIntoView()
.wait(100)

cy.contains('h1', 'Introduction')
.scrollIntoView()
.wait(100)
.get('[role=menuitem].active')
.should('have.text', 'Introduction');

cy.url().should('include', '#section/Introduction');
});

it('should update URL hash when clicking on menu items', () => {
cy.contains('[role=menuitem].-depth1', 'pet').click({ force: true });
cy.location('hash').should('equal', '#tag/pet');
Expand Down
1 change: 1 addition & 0 deletions src/services/MenuStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class MenuStore {

this.deactivate(this.activeItem);
if (!item) {
this.activeItemIdx = -1;
this.history.replace('', rewriteHistory);
return;
}
Expand Down