Skip to content

Commit

Permalink
Revert "Melsumner/issue 378 (#379)"
Browse files Browse the repository at this point in the history
This reverts commit 7fe1789.
  • Loading branch information
MelSumner authored Aug 8, 2024
1 parent 7fe1789 commit 1946f65
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 181 deletions.
16 changes: 7 additions & 9 deletions addon/components/navigation-narrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ export default class NavigationNarratorComponent extends Component {
/*
* @param hasQueryParams
* @type {boolean}
* @description Check for queryParams.
* @description Detect if the `transition.from` or the `transition.to` has queryParams.
* @default false
*/
get hasQueryParams() {
if (
Object.keys(this.transition.from.queryParams || {}).length ||
Object.keys(this.transition.to.queryParams).length > 0
) {
const qps =
(this.transition.from && this.transition.from.queryParams) ||
(this.transition.to && this.transition.to.queryParams);

if (qps && Object.keys(qps).length > 0) {
return true;
} else {
return false;
Expand All @@ -107,10 +108,7 @@ export default class NavigationNarratorComponent extends Component {
let shouldFocus;
this.transition = transition; // We need to do this because we can't pass an argument to a getter

// add a check to see if it's the same route (question: what if the user refreshes the page?)
let hasSameRoute = this.transition.from.name === this.transition.to.name;

if (this.excludeAllQueryParams && this.hasQueryParams && hasSameRoute) {
if (this.excludeAllQueryParams && this.hasQueryParams) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"npm-run-all2": "^5.0.0",
"prettier": "^2.5.1",
"qunit": "^2.17.2",
Expand Down
88 changes: 0 additions & 88 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 0 additions & 83 deletions tests/integration/components/navigation-narrator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,88 +173,5 @@ module('Integration | Component | navigation-narrator', function (hooks) {

assert.dom('#ember-a11y-refocus-nav-message').isFocused();
});

test('excludeAllQueryParams is true, queryParams do not exist but are added, do not manage focus', async function (assert) {
let router = this.owner.lookup('service:router');

await render(hbs`<NavigationNarrator @excludeAllQueryParams={{true}} />`);
router.trigger(
'routeDidChange',
new MockTransition({
from: new MockRouteInfo({
name: 'biscuit',
params: { id: 'hobnob' },
}),
to: new MockRouteInfo({
name: 'biscuit',
params: { id: 'hobnob' },
queryParams: { region: 'apac' },
}),
})
);

await settled();

assert.dom('#ember-a11y-refocus-nav-message').isNotFocused();
});

test('excludeAllQueryParams is true, queryParams exist on the route but then are emptied, still do not manage focus', async function (assert) {
let router = this.owner.lookup('service:router');

await render(hbs`<NavigationNarrator @excludeAllQueryParams={{true}} />`);
router.trigger(
'routeDidChange',
new MockTransition({
from: new MockRouteInfo({
name: 'biscuit',
params: { id: 'hobnob' },
queryParams: { region: 'apac' },
}),
to: new MockRouteInfo({
name: 'biscuit',
params: { id: 'hobnob' },
}),
})
);

await settled();

assert.dom('#ember-a11y-refocus-nav-message').isNotFocused();
});

test('excludeAllQueryParams is true, queryParams exist on the route, user navigates to new route without any query params, manage focus', async function (assert) {
let router = this.owner.lookup('service:router');

await render(hbs`<NavigationNarrator @excludeAllQueryParams={{true}} />`);
router.trigger(
'routeDidChange',
new MockTransition({
from: new MockRouteInfo({
name: 'biscuit',
params: { id: 'hobnob' },
queryParams: { region: 'apac' },
parent: new MockRouteInfo({
name: 'biscuits',
parent: new MockRouteInfo({
name: 'application',
}),
}),
}),
to: new MockRouteInfo({
name: 'index',
parent: new MockRouteInfo({
name: 'cakes',
parent: new MockRouteInfo({
name: 'application',
}),
}),
}),
})
);

await settled();

assert.dom('#ember-a11y-refocus-nav-message').isFocused();
});
});
});

0 comments on commit 1946f65

Please sign in to comment.