]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/src/mixin/Accessible.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / src / mixin / Accessible.js
CommitLineData
6527f429
DM
1/**\r
2 * This mixin defines certain config options, properties, and APIs to be used\r
3 * by Components that implement accessible traits according to WAI-ARIA 1.0 specification.\r
4 *\r
5 * @private\r
6 */\r
7Ext.define('Ext.mixin.Accessible', {\r
8 extend: 'Ext.Mixin',\r
9 \r
10 mixinConfig: {\r
11 id: 'accessible'\r
12 },\r
13 \r
14 /**\r
15 * @cfg {String} [ariaLabel] ARIA label for this Component. It is best to use\r
16 * {@link #ariaLabelledBy} option instead, because screen readers prefer\r
17 * `aria-labelledby` attribute to `aria-label`. {@link #ariaLabel} and\r
18 * {@link #ariaLabelledBy} config options are mutually exclusive.\r
19 */\r
20 \r
21 /**\r
22 * @cfg {String} [ariaLabelledBy] DOM selector for a child element that is to be used\r
23 * as label for this Component, set in `aria-labelledby` attribute.\r
24 * If the selector is by `#id`, the label element can be any existing element,\r
25 * not necessarily a child of the main Component element.\r
26 *\r
27 * {@link #ariaLabelledBy} and {@link #ariaLabel} config options are\r
28 * mutually exclusive, and `ariaLabelledBy` has the higher precedence.\r
29 */\r
30 \r
31 /**\r
32 * @cfg {String} [ariaDescribedBy] DOM selector for a child element that is to be used\r
33 * as description for this Component, set in `aria-describedby` attribute.\r
34 * The selector works the same way as {@link #ariaLabelledBy}.\r
35 */\r
36 \r
37 config: {\r
38 /**\r
39 * @cfg {Object} ariaAttributes An object containing ARIA attributes to be set\r
40 * on this Component's ARIA element. Use this to set the attributes that cannot be\r
41 * determined by the Component's state, such as `aria-live`, `aria-flowto`, etc.\r
42 *\r
43 * **Note** that this config is only meaningful at the Component rendering time,\r
44 * and setting it after that will do nothing.\r
45 */\r
46 ariaAttributes: {\r
47 $value: null,\r
48 lazy: true\r
49 }\r
50 },\r
51 \r
52 /**\r
53 * @property {String} [ariaRole] ARIA role for this Component, defaults to no role.\r
54 * With no role, no other ARIA attributes are set.\r
55 *\r
56 * @readonly\r
57 */\r
58 \r
59 /**\r
60 * @property {Object} [ariaRenderAttributes] **Instance specific** ARIA attributes\r
61 * to render into Component's ariaEl. This object is only used during rendering,\r
62 * and is discarded afterwards.\r
63 *\r
64 * @private\r
65 */\r
66 \r
67 privates: {\r
68 /**\r
69 * Find component(s) that label or describe this component,\r
70 * and return the id(s) of their ariaEl elements.\r
71 *\r
72 * @param {Function/String/String[]} [reference] Component reference,\r
73 * or array of component references, or a function that should return\r
74 * the proper attribute string. The function will be called in the\r
75 * context of the labelled component.\r
76 *\r
77 * @return {Ext.Element} Element id string, or null\r
78 * @private\r
79 */\r
80 getAriaLabelEl: function(selector) {\r
81 var ids = [],\r
82 refHolder, i, len, cmp, result;\r
83 \r
84 if (selector) {\r
85 if (Ext.isFunction(selector)) {\r
86 return selector.call(this);\r
87 }\r
88 else {\r
89 if (!Ext.isArray(selector)) {\r
90 selector = [selector];\r
91 }\r
92 \r
93 refHolder = this.lookupReferenceHolder();\r
94 \r
95 if (refHolder) {\r
96 for (i = 0, len = selector.length; i < len; i++) {\r
97 cmp = refHolder.lookupReference(selector[i]);\r
98 \r
99 if (cmp) {\r
100 ids.push(cmp.ariaEl.id);\r
101 }\r
102 }\r
103 }\r
104 }\r
105 }\r
106 \r
107 return ids.length ? ids.join(' ') : null;\r
108 }\r
109 }\r
110});\r