mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-30 19:08:54 +00:00
nested covers tabs should work with screen reader
This commit is contained in:
parent
b7bc089d86
commit
c37c6aae40
2 changed files with 20 additions and 26 deletions
|
@ -31,35 +31,23 @@ function rate_stars(e) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function tabChange(e) {
|
||||
var target = e.target.closest('li');
|
||||
|
||||
var parent_element = target.parentElement;
|
||||
var tabs = parent_element.getElementsByTagName('label');
|
||||
|
||||
parent_element.querySelectorAll('[aria-selected="true"]')
|
||||
.forEach(t => t.setAttribute("aria-selected", false));
|
||||
e.target.parentElement.setAttribute("aria-selected", true);
|
||||
|
||||
parent_element.querySelectorAll('li')
|
||||
.forEach(t => t.className='');
|
||||
target.className += ' is-active';
|
||||
}
|
||||
|
||||
function nestedTabChange(e) {
|
||||
function tabChange(e, nested) {
|
||||
var target = e.target.closest('li')
|
||||
var identifier = target.getAttribute('data-id');
|
||||
|
||||
if (nested) {
|
||||
var parent_element = target.parentElement.closest('li').parentElement;
|
||||
var tabs = parent_element.getElementsByTagName('label');
|
||||
for (i = 0; i < tabs.length; i++) {
|
||||
var tab = tabs[i].parentElement;
|
||||
if (tab.getAttribute('data-id') == identifier) {
|
||||
tab.className += ' is-active';
|
||||
} else {
|
||||
tab.className = tab.className.replace('is-active', '');
|
||||
}
|
||||
var parent_element = target.parentElement;
|
||||
}
|
||||
|
||||
parent_element.querySelectorAll('[aria-selected="true"]')
|
||||
.forEach(t => t.setAttribute("aria-selected", false));
|
||||
target.querySelector('[role="tab"]').setAttribute("aria-selected", true);
|
||||
|
||||
parent_element.querySelectorAll('li')
|
||||
.forEach(t => t.className='');
|
||||
target.className = 'is-active';
|
||||
}
|
||||
|
||||
function ajaxPost(form) {
|
||||
|
|
|
@ -21,7 +21,13 @@
|
|||
<ul>
|
||||
{% for book in shelf.books %}
|
||||
<li class="{% if shelf_counter == 1 and forloop.first %}is-active{% endif %}" data-id="tab-book-{{ book.id }}">
|
||||
<label for="book-{{ book.id }}" onclick="nestedTabChange(event)"><a>{% include 'snippets/book_cover.html' with book=book size="medium" %}</a></label>
|
||||
<label for="book-{{ book.id }}" onclick="tabChange(event, nested=true)">
|
||||
<div role="tab" tabindex="0" aria-selected="{% if shelf_counter == 1 and forloop.first %}true{% else %}false{% endif %}">
|
||||
<a>
|
||||
{% include 'snippets/book_cover.html' with book=book size="medium" %}
|
||||
</a>
|
||||
</div>
|
||||
</label>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue