This repository was archived by the owner on Jun 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathComboBoxData.js
More file actions
145 lines (135 loc) · 5.36 KB
/
Copy pathComboBoxData.js
File metadata and controls
145 lines (135 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { ROLES } from '../Roles';
import SelectData from './SelectData';
export default class ComboBoxData extends SelectData {
/**
* Adds a child display object to the ComboBox.
* Only allows children with specific roles that are valid for a ComboBox (e.g., textbox, search, button, etc.).
* Throws an error if the child does not have an allowed role.
* Calls the parent class's addChild method if valid.
* @inheritdoc
*/
addChild(displayObject) {
if (
!displayObject.accessible ||
(displayObject.accessible.role !== ROLES.SINGLELINETEXTBOX &&
displayObject.accessible.role !== ROLES.SEARCH &&
displayObject.accessible.role !== ROLES.BUTTON &&
displayObject.accessible.role !== ROLES.SINGLESELECTLISTBOX &&
displayObject.accessible.role !== ROLES.TREE &&
displayObject.accessible.role !== ROLES.GRID &&
displayObject.accessible.role !== ROLES.DIALOG)
) {
throw new Error(
`Children of ${this.role} must have a role of ${ROLES.SINGLELINETEXTBOX}, ${ROLES.SEARCH}, ${ROLES.BUTTON}, ${ROLES.SINGLESELECTLISTBOX}, ${ROLES.TREE}, ${ROLES.GRID}, or ${ROLES.DIALOG}`
);
}
super.addChild(displayObject);
}
/**
* Adds a child display object to the ComboBox at a specific index.
* Only allows children with specific roles that are valid for a ComboBox (e.g., textbox, search, button, etc.).
* Throws an error if the child does not have an allowed role.
* Calls the parent class's addChildAt method if valid.
* @inheritdoc
*/
addChildAt(displayObject, index) {
if (
!displayObject.accessible ||
(displayObject.accessible.role !== ROLES.SINGLELINETEXTBOX &&
displayObject.accessible.role !== ROLES.SEARCH &&
displayObject.accessible.role !== ROLES.BUTTON &&
displayObject.accessible.role !== ROLES.SINGLESELECTLISTBOX &&
displayObject.accessible.role !== ROLES.TREE &&
displayObject.accessible.role !== ROLES.GRID &&
displayObject.accessible.role !== ROLES.DIALOG)
) {
throw new Error(
`Children of ${this.role} must have a role of ${ROLES.SINGLELINETEXTBOX}, ${ROLES.SEARCH}, ${ROLES.BUTTON}, ${ROLES.SINGLESELECTLISTBOX}, ${ROLES.TREE}, ${ROLES.GRID}, or ${ROLES.DIALOG}`
);
}
super.addChildAt(displayObject, index);
}
/**
* Enables or disables the autocomplete feature for the ComboBox.
* When enabled, the browser may suggest or automatically complete user input based on previous entries.
* Sets the 'autoComplete' property in the underlying React props to 'on' or 'off'.
* @access public
* @param {boolean} enable - true to enable autocomplete, false to disable.
*/
set autoComplete(enable) {
this._reactProps.autoComplete = enable ? 'on' : 'off';
}
/**
* Returns whether autocomplete is enabled for the ComboBox.
* Checks the 'autoComplete' property in the underlying React props.
* Returns true if autocomplete is enabled (either by default or explicitly), false otherwise.
* @access public
* @returns {boolean} true if autocomplete is enabled, false otherwise.
*/
get autoComplete() {
return (
this._reactProps.autoComplete === undefined ||
this._reactProps.autoComplete === 'on'
);
}
/**
* Sets the expanded state of the ComboBox.
* When expanded, the ComboBox's options are visible to the user.
* Sets the 'aria-expanded' property in the underlying React props.
* @access public
* @param {boolean} val - true if expanded, false if collapsed, undefined if unset.
*/
set expanded(val) {
this._reactProps['aria-expanded'] = val;
}
/**
* Returns the expanded state of the ComboBox.
* Checks the 'aria-expanded' property in the underlying React props.
* Returns true if expanded, false if collapsed, undefined if unset.
* @access public
* @returns {boolean|undefined} true if expanded, false if collapsed, undefined if unset.
*/
get expanded() {
return this._reactProps['aria-expanded'];
}
/**
* Sets the read-only state of the ComboBox.
* When set to true, the ComboBox cannot be edited by the user.
* Sets the 'aria-readonly' property in the underlying React props.
* @access public
* @param {boolean} value - true to make read-only, false to make editable.
*/
set readOnly(value) {
this._reactProps['aria-readonly'] = value;
}
/**
* Returns the read-only state of the ComboBox.
* Checks the 'aria-readonly' property in the underlying React props.
* Returns true if read-only, false if editable.
* @access public
* @returns {boolean} true if read-only, false if editable.
*/
get readOnly() {
return this._reactProps['aria-readonly'];
}
/**
* Sets whether user input is required for the ComboBox.
* When set to true, the ComboBox must be filled out before submitting a form.
* Sets the 'aria-required' property in the underlying React props.
* @access public
* @param {boolean} value - true if required, false otherwise.
*/
set required(value) {
this._reactProps['aria-required'] = value;
}
/**
* Returns whether user input is required for the ComboBox.
* Checks the 'aria-required' property in the underlying React props.
* Returns true if required, false otherwise.
* @access public
* @returns {boolean} true if required, false otherwise.
*/
get required() {
return this._reactProps['aria-required'];
}
}