backport of commit 30a9b6eda74e515135dbebb600b362da6d637cb1 (#18256)

Co-authored-by: Phil Renaud <phil.renaud@hashicorp.com>
This commit is contained in:
hc-github-team-nomad-core 2023-09-06 08:25:51 -05:00 committed by GitHub
parent 428711a903
commit 71f8405b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

3
.changelog/18210.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
ui: adds keyboard commands for pagination on lists using [[ and ]]
```

View File

@ -19,5 +19,6 @@ module.exports = {
},
ignore: [
'app/components/breadcrumbs/*', // using {{(modifier)}} syntax
'app/templates/components/list-pagination/list-pager', // using {{(modifier)}} syntax
],
};

View File

@ -6,7 +6,29 @@
import Component from '@ember/component';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import KeyboardShortcutModifier from 'nomad-ui/modifiers/keyboard-shortcut';
@classic
@tagName('')
export default class ListPager extends Component {}
export default class ListPager extends Component {
@service router;
// Even though we don't currently use "first" / "last" pagination in the app,
// the option is there at a component level, so let's make sure that we
// only append keyNav to the "next" and "prev" links.
// We use this to make the modifier conditional, per https://v5.chriskrycho.com/journal/conditional-modifiers-and-helpers-in-emberjs/
get includeKeyboardNav() {
return this.label === 'Next page' || this.label === 'Previous page'
? KeyboardShortcutModifier
: null;
}
@action
gotoRoute() {
this.router.transitionTo(this.router.currentRouteName, {
queryParams: { page: this.page },
});
}
}

View File

@ -9,6 +9,12 @@
class={{this.class}}
data-test-pager={{this.test}}
aria-label={{this.label}}
{{(modifier
this.includeKeyboardNav
label=(if (eq this.label 'Next page') 'Next Page' 'Previous Page')
action=(action "gotoRoute")
pattern=(if (eq this.label 'Next page') (array "]" "]") (array "[" "["))
)}}
>
{{yield}}
</LinkTo>