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

Migrate core/utils/aria.js to goog.module. #5067

Merged
merged 6 commits into from
Aug 12, 2021
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
40 changes: 21 additions & 19 deletions core/utils/aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/**
* @fileoverview Constant declarations for common key codes.
* @fileoverview ARIA-related constants and utilities.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @author samelh@google.com (Sam El-Husseini)
Expand All @@ -16,27 +16,22 @@
* @name Blockly.utils.aria
* @namespace
*/
goog.provide('Blockly.utils.aria');
goog.module('Blockly.utils.aria');
goog.module.declareLegacyNamespace();


/**
* ARIA states/properties prefix.
* @private
*/
Blockly.utils.aria.ARIA_PREFIX_ = 'aria-';
/** ARIA states/properties prefix. */
const ARIA_PREFIX = 'aria-';

/**
* ARIA role attribute.
* @private
*/
Blockly.utils.aria.ROLE_ATTRIBUTE_ = 'role';
/** ARIA role attribute. */
const ROLE_ATTRIBUTE = 'role';

/**
* ARIA role values.
* Copied from Closure's goog.a11y.aria.Role
* @enum {string}
*/
Blockly.utils.aria.Role = {
const Role = {
// ARIA role for an interactive control of tabular data.
GRID: 'grid',

Expand Down Expand Up @@ -80,7 +75,7 @@ Blockly.utils.aria.Role = {
* Copied from Closure's goog.a11y.aria.State
* @enum {string}
*/
Blockly.utils.aria.State = {
const State = {
// ARIA property for setting the currently active descendant of an element,
// for example the selected item in a list box. Value: ID of an element.
ACTIVEDESCENDANT: 'activedescendant',
Expand Down Expand Up @@ -148,24 +143,31 @@ Blockly.utils.aria.State = {
* @param {!Element} element DOM node to set role of.
* @param {!Blockly.utils.aria.Role} roleName Role name.
*/
Blockly.utils.aria.setRole = function(element, roleName) {
element.setAttribute(Blockly.utils.aria.ROLE_ATTRIBUTE_, roleName);
const setRole = function(element, roleName) {
element.setAttribute(ROLE_ATTRIBUTE, roleName);
};

/**
* Sets the state or property of an element.
* Copied from Closure's goog.a11y.aria
* @param {!Element} element DOM node where we set state.
* @param {!Blockly.utils.aria.State} stateName State attribute being set.
* @param {!State} stateName State attribute being set.
* Automatically adds prefix 'aria-' to the state name if the attribute is
* not an extra attribute.
* @param {string|boolean|number|!Array<string>} value Value
* for the state attribute.
*/
Blockly.utils.aria.setState = function(element, stateName, value) {
const setState = function(element, stateName, value) {
if (Array.isArray(value)) {
value = value.join(' ');
}
var attrStateName = Blockly.utils.aria.ARIA_PREFIX_ + stateName;
const attrStateName = ARIA_PREFIX + stateName;
element.setAttribute(attrStateName, value);
};

exports = {
Role,
State,
setRole,
setState,
};
2 changes: 1 addition & 1 deletion tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.