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

Remove PublicationMenuComponent render modifiers #8264

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 4 deletions packages/ilios-common/.lint-todo
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628da
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|32658810aa13672f5981281c562729112a89788f|1731542400000|1762646400000|1793750400000|addon/components/course/header.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1731542400000|1762646400000|1793750400000|addon/components/course/objective-list.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|84076f8cf85c554eaf0d9fdec26154bae5bceeb2|1731542400000|1762646400000|1793750400000|addon/components/course/objective-list.hbs
add|ember-template-lint|no-at-ember-render-modifiers|28|6|28|6|1ef231a97c0ec761eaafb3e76093515e5523ff27|1731542400000|1762646400000|1793750400000|addon/components/course/publication-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|29|6|29|6|df94e6558ff62dea69f6f656f668f29b56bcc378|1731542400000|1762646400000|1793750400000|addon/components/course/publication-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|2bbf15957242a9a3c1e26e14e5d022c858199fde|1731542400000|1762646400000|1793750400000|addon/components/course/rollover-date-picker.hbs
add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|167e8d9ede488c7f199cb748e81bc09b97617e71|1731542400000|1762646400000|1793750400000|addon/components/course/rollover-date-picker.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|1009d3843f6aed52099f0e7fbd4eebb52bc176e5|1731542400000|1762646400000|1793750400000|addon/components/course/rollover.hbs
Expand All @@ -55,5 +53,3 @@ add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|23cd787c79c34a628da
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|23cd787c79c34a628dadb6e96dd4004d42eebb79|1731542400000|1762646400000|1793750400000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|a90be151f45cd8ab32827e9247a9a9eb7f1baef2|1731542400000|1762646400000|1793750400000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|24|10|24|10|2ed3ce70b879732dc85047f9f546c5dbd5376dba|1731542400000|1762646400000|1793750400000|addon/components/dashboard/courses-calendar-filter.hbs
add|ember-template-lint|no-at-ember-render-modifiers|28|6|28|6|1ef231a97c0ec761eaafb3e76093515e5523ff27|1731542400000|1762646400000|1793750400000|addon/components/session/publication-menu.hbs
add|ember-template-lint|no-at-ember-render-modifiers|29|6|29|6|df94e6558ff62dea69f6f656f668f29b56bcc378|1731542400000|1762646400000|1793750400000|addon/components/session/publication-menu.hbs
204 changes: 99 additions & 105 deletions packages/ilios-common/addon/components/course/publication-menu.hbs
Original file line number Diff line number Diff line change
@@ -1,107 +1,101 @@
<div
role="menubar"
class="publication-menu {{this.publicationStatus}}"
data-test-course-publication-menu
{{on-click-outside (set this "isOpen" false)}}
>
<button
aria-label={{this.title}}
role="menuitem"
class="toggle"
aria-haspopup="true"
aria-expanded={{if this.isOpen "true" "false"}}
type="button"
data-test-toggle
{{on "click" (toggle "isOpen" this)}}
{{on "keyup" this.toggleMenu}}
{{#let (unique-id) as |templateId|}}
<div
role="menubar"
class="publication-menu {{this.publicationStatus}}"
id="menu-{{templateId}}"
data-test-course-publication-menu
{{on-click-outside (set this "isOpen" false)}}
>
<FaIcon @icon={{this.icon}} />
<span>
{{this.title}}
</span>
<FaIcon @icon={{if this.isOpen "caret-down" "caret-right"}} />
</button>
{{#if this.isOpen}}
<div
class="menu"
role="menu"
{{did-insert (set this "menuElement")}}
{{did-insert this.focusOnFirstItem}}
data-test-menu
<button
aria-label={{this.title}}
role="menuitem"
class="toggle"
aria-haspopup="true"
aria-expanded={{if this.isOpen "true" "false"}}
type="button"
data-test-toggle
{{on "keyup" this.keyUp}}
{{on "click" this.toggleMenu}}
>
{{#if this.showAsIs}}
<button
class="danger"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publish}}
{{on "keyup" this.moveFocus}}
{{on "mouseenter" this.clearFocus}}
data-test-publish-as-is
>
{{t "general.publishAsIs"}}
</button>
{{/if}}
{{#if this.showPublish}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publish}}
{{on "keyup" this.moveFocus}}
{{on "mouseenter" this.clearFocus}}
data-test-publish
>
{{t "general.publishCourse"}}
</button>
{{/if}}
{{#if this.showReview}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.scrollToCoursePublication}}
{{on "keyup" this.moveFocus}}
{{on "mouseenter" this.clearFocus}}
data-test-review
>
{{t
"general.reviewMissingItems"
count=(get @course "allPublicationIssuesLength")
}}
</button>
{{/if}}
{{#if this.showTbd}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publishAsTbd}}
{{on "keyup" this.moveFocus}}
{{on "mouseenter" this.clearFocus}}
data-test-tbd
>
{{t "general.markAsScheduled"}}
</button>
{{/if}}
{{#if this.showUnPublish}}
<button
class="danger"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.unpublish}}
{{on "keyup" this.moveFocus}}
{{on "mouseenter" this.clearFocus}}
data-test-un-publish
>
{{t "general.unPublishCourse"}}
</button>
{{/if}}
</div>
{{/if}}
</div>
<FaIcon @icon={{this.icon}} />
<span>
{{this.title}}
</span>
<FaIcon @icon={{if this.isOpen "caret-down" "caret-right"}} />
</button>
{{#if this.isOpen}}
<div class="menu" role="menu" data-test-menu {{focus}}>
{{#if this.showAsIs}}
<button
class="danger"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publish}}
{{on "keyup" this.keyUp}}
{{on "mouseenter" this.clearFocus}}
data-test-publish-as-is
>
{{t "general.publishAsIs"}}
</button>
{{/if}}
{{#if this.showPublish}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publish}}
{{on "keyup" this.keyUp}}
{{on "mouseenter" this.clearFocus}}
data-test-publish
>
{{t "general.publishCourse"}}
</button>
{{/if}}
{{#if this.showReview}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.scrollToCoursePublication}}
{{on "keyup" this.keyUp}}
{{on "mouseenter" this.clearFocus}}
data-test-review
>
{{t "general.reviewMissingItems" count=(get @course "allPublicationIssuesLength")}}
</button>
{{/if}}
{{#if this.showTbd}}
<button
class="good"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.publishAsTbd}}
{{on "keyup" this.keyUp}}
{{on "mouseenter" this.clearFocus}}
data-test-tbd
>
{{t "general.markAsScheduled"}}
</button>
{{/if}}
{{#if this.showUnPublish}}
<button
class="danger"
role="menuitem"
tabindex="-1"
type="button"
{{on "click" this.unpublish}}
{{on "keyup" this.keyUp}}
{{on "mouseenter" this.clearFocus}}
data-test-un-publish
>
{{t "general.unPublishCourse"}}
</button>
{{/if}}
</div>
{{/if}}
</div>
{{/let}}
69 changes: 42 additions & 27 deletions packages/ilios-common/addon/components/course/publication-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { task, timeout } from 'ember-concurrency';

export default class CoursePublicationMenuComponent extends Component {
@service router;
Expand Down Expand Up @@ -63,53 +64,67 @@ export default class CoursePublicationMenuComponent extends Component {
return 'notpublished';
}

focusOnFirstItem(menuElement) {
menuElement.querySelector('button:first-of-type').focus();
focusFirstLink = task(async () => {
await timeout(1);
document.querySelector('.publication-menu .menu button:first-of-type').focus();
Copy link
Member

Choose a reason for hiding this comment

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

this works since there's only ever one menu open at the same time.
however, querying from the doc root is brittle.

i'm suggesting bringing the menu element back as input argument, then making the DOM query from that element instead.

would require identifying the menu element from the event target in the click handler -for example, if the clicked element is nested within the menu ("menu item"), you'll have to traverse the DOM tree up from it.

});

handleArrowUp(item) {
if (item?.previousElementSibling) {
item.previousElementSibling.focus();
} else {
item?.parentElement.lastElementChild.focus();
}
}

async handleArrowDown(item) {
if (item.classList.value == 'toggle') {
this.isOpen = true;
await this.focusFirstLink.perform();
} else {
if (item.nextElementSibling) {
item.nextElementSibling.focus();
} else {
await this.focusFirstLink.perform();
}
}
}

@action
moveFocus({ key, target }) {
async toggleMenu() {
this.isOpen = !this.isOpen;

if (this.isOpen) {
await this.focusFirstLink.perform();
}
}
@action
keyUp({ key, target }) {
switch (key) {
case 'ArrowDown':
if (target.nextElementSibling) {
target.nextElementSibling.focus();
} else {
this.menuElement.querySelector('button:nth-of-type(1)').focus();
}
this.handleArrowDown(target);
break;
case 'ArrowUp':
if (target.previousElementSibling) {
target.previousElementSibling.focus();
} else {
this.menuElement.querySelector('button:last-of-type').focus();
}
this.handleArrowUp(target);
break;
case 'Escape':
case 'Tab':
case 'ArrowRight':
case 'ArrowLeft':
this.isOpen = false;
this.close();
break;
}

return false;
}
@action
clearFocus() {
const buttons = this.menuElement.querySelectorAll('button');
const buttons = document.querySelectorAll('.publication-menu .menu button');
buttons.forEach((el) => el.blur());
}
@action
toggleMenu({ key }) {
switch (key) {
case 'ArrowDown':
this.isOpen = true;
break;
case 'Escape':
case 'Tab':
case 'ArrowRight':
case 'ArrowLeft':
this.isOpen = false;
break;
}
close() {
this.isOpen = false;
}

@action
Expand Down
Loading
Loading