Skip to content

Commit

Permalink
Merge pull request #5067 from maribethb/module_aria
Browse files Browse the repository at this point in the history
Migrate core/utils/aria.js to goog.module.
  • Loading branch information
maribethb authored Aug 12, 2021
2 parents 26a0556 + 13fdf60 commit a0bf18c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
37 changes: 18 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.
* 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 @@ -74,13 +69,14 @@ Blockly.utils.aria.Role = {
// ARIA role for a tree item that sometimes may be expanded or collapsed.
TREEITEM: 'treeitem'
};
exports.Role = Role;

/**
* ARIA states and properties.
* 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 @@ -139,6 +135,7 @@ Blockly.utils.aria.State = {
// ARIA property for slider minimum value. Value: number.
VALUEMIN: 'valuemin'
};
exports.State = State;

/**
* Sets the role of an element.
Expand All @@ -148,24 +145,26 @@ 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);
};
exports.setRole = setRole;

/**
* 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.setState = 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.

0 comments on commit a0bf18c

Please sign in to comment.