-
Notifications
You must be signed in to change notification settings - Fork 7
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
Bookmark all can be activated by spacebar #4770
Open
rladdusaw
wants to merge
3
commits into
main
Choose a base branch
from
4760-bookmark-all-tab-order
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import BookmarkAllManager from '../../../app/javascript/orangelight/bookmark_all.es6'; | ||
describe('BookmarkAllManager', () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<div id="content" class="col-12 col-md-8"> | ||
<div id="sortAndPerPage" class="clearfix"> | ||
<div class="search-widgets float-end"> | ||
<div class="checkbox bookmark_all" tabindex="0"> | ||
<label for="bookmark_all_input"> | ||
<input type="checkbox" id="bookmark_all_input"> | ||
<span>Bookmark all</span> | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
<h2 class="visually-hidden visually-hidden">Search Results</h2> | ||
<div id="documents" class="documents-list"> | ||
<article data-document-id="99122304923506421" data-document-counter="1" itemscope="itemscope" itemtype="http://schema.org/Thing" class="blacklight-book document document-position-1"> | ||
<div class="row search-result-wrapper"> | ||
<div class="record-wrapper"> | ||
<header class="documentHeader"> | ||
<h3 class="index_title document-title-heading col"> | ||
<span class="document-counter">1. </span><a data-context-href="/catalog/99122304923506421/track?counter=1&document_id=99122304923506421&per_page=20&search_id=111" data-context-method="post" data-turbo-prefetch="false" itemprop="name" dir="ltr" href="/catalog/99122304923506421">Ahmet Kutsi Tecer sempozyum bildirileri : Sıvas 24 - 27 Nisan 2018 / editör Teoman Karaca.</a></h3> | ||
</header> | ||
<ul class="document-metadata dl-horizontal dl-invert"> | ||
<li><ul><li><a class="search-name" data-original-title="Search: Ahmet Kutsi Tecer Sempozyumu (2018 : Sivas, Turkey)" href="/?f[author_s][]=Ahmet+Kutsi+Tecer+Sempozyumu+%282018+%3A+Sivas%2C+Turkey%29">Ahmet Kutsi Tecer Sempozyumu (2018 : Sivas, Turkey)</a> <a class="browse-name" data-original-title="Browse: Ahmet Kutsi Tecer Sempozyumu (2018 : Sivas, Turkey)" dir="ltr" href="/browse/names?q=Ahmet+Kutsi+Tecer+Sempozyumu+%282018+%3A+Sivas%2C+Turkey%29">[Browse]</a></li></ul></li> | ||
<li><ul><li>Sıvas : Sıvas İl Kültür Turizm Müdürlüğü, [2019]</li></ul></li> | ||
<li><ul><li><ul><li class="blacklight-format" dir="ltr"> <span class="icon icon-book" aria-hidden="true"></span> Book </li></ul></li></ul></li> | ||
</ul> | ||
</div> | ||
<div class="thumbnail-wrapper"> | ||
<form class="bookmark-toggle" data-present="In Bookmarks" data-absent="Bookmark" data-inprogress="Saving..." action="/bookmarks/99127972072106421" accept-charset="UTF-8" method="post"> | ||
<input type="hidden" name="_method" value="put" autocomplete="off"> | ||
<div class="checkbox toggle-bookmark"> | ||
<label class="toggle-bookmark" data-checkboxsubmit-target="label"> | ||
<input type="checkbox" class="toggle-bookmark " data-checkboxsubmit-target="checkbox"> | ||
<span data-checkboxsubmit-target="span">Bookmark</span> | ||
</label> | ||
</div> | ||
<input type="submit" name="commit" value="Bookmark" class="bookmark-add btn btn-outline-secondary" data-disable-with="Bookmark"> | ||
</form> | ||
</div> | ||
</div> | ||
</article> | ||
<article data-document-id="99127972072106421" data-document-counter="2" itemscope="itemscope" itemtype="http://schema.org/Thing" class="blacklight-book document document-position-2"> | ||
<div class="row search-result-wrapper"> | ||
<div class="record-wrapper"> | ||
<header class="documentHeader"> | ||
<h3 class="index_title document-title-heading col"> | ||
<span class="document-counter">2. </span><a data-context-href="/catalog/99127972072106421/track?counter=2&document_id=99127972072106421&per_page=20&search_id=111" data-context-method="post" data-turbo-prefetch="false" itemprop="name" dir="ltr" href="/catalog/99127972072106421">Dancing Black, dancing White : rock 'n' roll, race, and youth culture of the 1950s and early 1960s / Julie Malnig.</a></h3> | ||
</header> | ||
<ul class="document-metadata dl-horizontal dl-invert"> | ||
<li><ul><li><a class="search-name" data-original-title="Search: Malnig, Julie" href="/?f[author_s][]=Malnig%2C+Julie">Malnig, Julie</a> <a class="browse-name" data-original-title="Browse: Malnig, Julie" dir="ltr" href="/browse/names?q=Malnig%2C+Julie">[Browse]</a></li></ul></li> | ||
<li><ul><li>New York, NY : Oxford University Press, [2023]</li></ul></li> | ||
<li><ul><li><ul><li class="blacklight-format" dir="ltr"> <span class="icon icon-book" aria-hidden="true"></span> Book </li></ul></li></ul></li> | ||
</ul> | ||
</div> | ||
<div class="thumbnail-wrapper"> | ||
<form class="bookmark-toggle" data-present="In Bookmarks" data-absent="Bookmark" data-inprogress="Saving..." action="/bookmarks/99127972072106421" accept-charset="UTF-8" method="post"> | ||
<input type="hidden" name="_method" value="put" autocomplete="off"> | ||
<div class="checkbox toggle-bookmark"> | ||
<label class="toggle-bookmark" data-checkboxsubmit-target="label"> | ||
<input type="checkbox" class="toggle-bookmark " data-checkbox submit-target="checkbox"> | ||
<span data-checkboxsubmit-target="span">Bookmark</span> | ||
</label> | ||
</div> | ||
<input type="submit" name="commit" value="Bookmark" class="bookmark-add btn btn-outline-secondary" data-disable-with="Bookmark"> | ||
</form> | ||
</div> | ||
</div> | ||
</article> | ||
<article data-document-id="99125476820706421" data-document-counter="3" itemscope="itemscope" itemtype="http://schema.org/Thing" class="blacklight-book document document-position-3"> | ||
<div class="row search-result-wrapper"> | ||
<div class="record-wrapper"> | ||
<header class="documentHeader"> | ||
<h3 class="index_title document-title-heading col"> | ||
<span class="document-counter">3. </span><a data-context-href="/catalog/99125476820706421/track?counter=3&document_id=99125476820706421&per_page=20&search_id=111" data-context-method="post" data-turbo-prefetch="false" itemprop="name" dir="ltr" href="/catalog/99125476820706421">Black youth aspirations : imagined futures and transitions into adulthood / by Botshabelo Maja (Independent Scholar, Republic of South Africa).</a></h3> | ||
</header> | ||
<ul class="document-metadata dl-horizontal dl-invert"> | ||
<li><ul><li><a class="search-name" data-original-title="Search: Maja, Botshabelo" href="/?f[author_s][]=Maja%2C+Botshabelo">Maja, Botshabelo</a> <a class="browse-name" data-original-title="Browse: Maja, Botshabelo" dir="ltr" href="/browse/names?q=Maja%2C+Botshabelo">[Browse]</a></li></ul></li> | ||
<li><ul><li><ul id="pub_created_display-list"><li class="blacklight-pub_created_display" dir="ltr">United Kingdom : Emerald Publishing Limited, 2022.</li><li class="blacklight-pub_created_display" dir="ltr">©2022</li></ul></li></ul></li> | ||
<li><ul><li><ul><li class="blacklight-format" dir="ltr"> <span class="icon icon-book" aria-hidden="true"></span> Book </li></ul></li></ul></li> | ||
</ul> | ||
</div> | ||
<div class="thumbnail-wrapper"> | ||
<form class="bookmark-toggle" data-present="In Bookmarks" data-absent="Bookmark" data-inprogress="Saving..." action="/bookmarks/99125476820706421" accept-charset="UTF-8" method="post"> | ||
<input type="hidden" name="_method" value="put" autocomplete="off"> | ||
<div class="checkbox toggle-bookmark"> | ||
<label class="toggle-bookmark" data-checkboxsubmit-target="label"> | ||
<input type="checkbox" class="toggle-bookmark " data-checkboxsubmit-target="checkbox"> | ||
<span data-checkboxsubmit-target="span">Bookmark</span> | ||
</label> | ||
</div> | ||
<input type="submit" name="commit" value="Bookmark" class="bookmark-add btn btn-outline-secondary" data-disable-with="Bookmark"> | ||
</form> | ||
</div> | ||
</div> | ||
</article> | ||
</div> | ||
</div>`; | ||
new BookmarkAllManager(); | ||
}); | ||
describe('press space on bookmark all button', () => { | ||
it('Selects all the bookmark checkboxes', () => { | ||
const bookmark_all_div = document.querySelector('.bookmark_all'); | ||
const press_space = new KeyboardEvent('keydown', { | ||
key: ' ', | ||
code: 'Space', | ||
which: 32, | ||
keyCode: 32, | ||
}); | ||
expect(bookmark_all_input.checked).toBe(false); | ||
let bookmark_checkboxes = document.querySelectorAll( | ||
'input.toggle-bookmark:not(:checked)' | ||
); | ||
expect(bookmark_checkboxes.length).toBe(3); | ||
bookmark_all_div.dispatchEvent(press_space); | ||
bookmark_checkboxes = document.querySelectorAll( | ||
'input.toggle-bookmark:checked' | ||
); | ||
expect(bookmark_checkboxes.length).toBe(3); | ||
bookmark_all_div.dispatchEvent(press_space); | ||
bookmark_checkboxes = document.querySelectorAll( | ||
'input.toggle-bookmark:not(:checked)' | ||
); | ||
expect(bookmark_checkboxes.length).toBe(3); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a button, rather than a div here? Then we could listen for a click event to catch either the space bar or the enter key. It would also get added to the tab order automatically, without having to specify tabindex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a quick test, but it messed up the styling pretty badly. I could do it, but it might take a while to sort out the css.
I added the enter key to the event listener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! I think the button would be better long term (we wouldn't need to remember the tabindex if we refactor this code in the future, for example), if you can get the CSS sorted. Another benefit is that the button would be navigable by assistive technologies that allow you to navigate by form control (like NVDA).