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

Listbox Patternを日本語化 #143

Open
wants to merge 2 commits into
base: waic-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
29 changes: 18 additions & 11 deletions content/patterns/listbox/examples/css/listbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,30 @@
[role="option"] {
position: relative;
display: block;
padding: 0 1em 0 1.5em;
margin: 2px;
padding: 2px 1em 2px 1.5em;
line-height: 1.8em;
cursor: pointer;
}

[role="option"].focused {
[role="listbox"]:focus [role="option"].focused {
background: #bde4ff;
}

[role="option"][aria-selected="true"]::before {
[role="listbox"]:focus [role="option"].focused,
[role="option"]:hover {
outline: 2px solid currentcolor;
}

.move-right-btn span.checkmark::after {
content: " →";
}

.move-left-btn span.checkmark::before {
content: "← ";
}

[role="option"][aria-selected="true"] span.checkmark::before {
position: absolute;
left: 0.5em;
content: "✓";
Expand Down Expand Up @@ -120,14 +135,6 @@ button[aria-disabled="true"] {
opacity: 0.5;
}

.move-right-btn::after {
content: " →";
}

.move-left-btn::before {
content: "← ";
}

.annotate {
color: #366ed4;
font-style: italic;
Expand Down
124 changes: 67 additions & 57 deletions content/patterns/listbox/examples/js/listbox-collapsible.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*/

'use strict';

/**
* @namespace aria
* @description
* The aria namespace is used to support sharing class definitions between example files
* without causing eslint errors for undefined classes
*/
var aria = aria || {};

/**
* ARIA Collapsible Dropdown Listbox Example
*
Expand All @@ -7,70 +21,66 @@
*/

window.addEventListener('load', function () {
var button = document.getElementById('exp_button');
var exListbox = new aria.Listbox(document.getElementById('exp_elem_list'));
new aria.ListboxButton(button, exListbox);
const button = document.getElementById('exp_button');
const exListbox = new aria.Listbox(document.getElementById('exp_elem_list'));
new ListboxButton(button, exListbox);
});

var aria = aria || {};

aria.ListboxButton = function (button, listbox) {
this.button = button;
this.listbox = listbox;
this.registerEvents();
};

aria.ListboxButton.prototype.registerEvents = function () {
this.button.addEventListener('click', this.showListbox.bind(this));
this.button.addEventListener('keyup', this.checkShow.bind(this));
this.listbox.listboxNode.addEventListener(
'blur',
this.hideListbox.bind(this)
);
this.listbox.listboxNode.addEventListener(
'keydown',
this.checkHide.bind(this)
);
this.listbox.setHandleFocusChange(this.onFocusChange.bind(this));
};

aria.ListboxButton.prototype.checkShow = function (evt) {
var key = evt.which || evt.keyCode;
class ListboxButton {
constructor(button, listbox) {
this.button = button;
this.listbox = listbox;
this.registerEvents();
}

switch (key) {
case aria.KeyCode.UP:
case aria.KeyCode.DOWN:
evt.preventDefault();
this.showListbox();
this.listbox.checkKeyPress(evt);
break;
registerEvents() {
this.button.addEventListener('click', this.showListbox.bind(this));
this.button.addEventListener('keyup', this.checkShow.bind(this));
this.listbox.listboxNode.addEventListener(
'blur',
this.hideListbox.bind(this)
);
this.listbox.listboxNode.addEventListener(
'keydown',
this.checkHide.bind(this)
);
this.listbox.setHandleFocusChange(this.onFocusChange.bind(this));
}
};

aria.ListboxButton.prototype.checkHide = function (evt) {
var key = evt.which || evt.keyCode;
checkShow(evt) {
switch (evt.key) {
case 'ArrowUp':
case 'ArrowDown':
evt.preventDefault();
this.showListbox();
this.listbox.checkKeyPress(evt);
break;
}
}

switch (key) {
case aria.KeyCode.RETURN:
case aria.KeyCode.ESC:
evt.preventDefault();
this.hideListbox();
this.button.focus();
break;
checkHide(evt) {
switch (evt.key) {
case 'Enter':
case 'Escape':
evt.preventDefault();
this.hideListbox();
this.button.focus();
break;
}
}
};

aria.ListboxButton.prototype.showListbox = function () {
aria.Utils.removeClass(this.listbox.listboxNode, 'hidden');
this.button.setAttribute('aria-expanded', 'true');
this.listbox.listboxNode.focus();
};
showListbox() {
this.listbox.listboxNode.classList.remove('hidden');
this.button.setAttribute('aria-expanded', 'true');
this.listbox.listboxNode.focus();
}

aria.ListboxButton.prototype.hideListbox = function () {
aria.Utils.addClass(this.listbox.listboxNode, 'hidden');
this.button.removeAttribute('aria-expanded');
};
hideListbox() {
this.listbox.listboxNode.classList.add('hidden');
this.button.removeAttribute('aria-expanded');
}

aria.ListboxButton.prototype.onFocusChange = function (focusedItem) {
this.button.innerText = focusedItem.innerText;
};
onFocusChange(focusedItem) {
this.button.innerText = focusedItem.innerText;
}
}
10 changes: 8 additions & 2 deletions content/patterns/listbox/examples/js/listbox-rearrangeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*/

/* global aria */

'use strict';

/**
* @namespace aria
* @description
* The aria namespace is used to support sharing class definitions between example files
* without causing eslint errors for undefined classes
*/
var aria = aria || {};

/**
* ARIA Listbox Examples
*
Expand Down
10 changes: 8 additions & 2 deletions content/patterns/listbox/examples/js/listbox-scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*/

/* global aria */

'use strict';

/**
* @namespace aria
* @description
* The aria namespace is used to support sharing class definitions between example files
* without causing eslint errors for undefined classes
*/
var aria = aria || {};

/**
* ARIA Scrollable Listbox Example
*
Expand Down
Loading