|
@@ -12,6 +12,69 @@ import type { Props } from './AbstractToolboxItem';
|
12
|
12
|
* Web implementation of {@code AbstractToolboxItem}.
|
13
|
13
|
*/
|
14
|
14
|
export default class ToolboxItem extends AbstractToolboxItem<Props> {
|
|
15
|
+ /**
|
|
16
|
+ * Initializes a new {@code ToolboxItem} instance.
|
|
17
|
+ *
|
|
18
|
+ * @inheritdoc
|
|
19
|
+ */
|
|
20
|
+ constructor(props: Props) {
|
|
21
|
+ super(props);
|
|
22
|
+
|
|
23
|
+ this._onKeyDown = this._onKeyDown.bind(this);
|
|
24
|
+ this._onKeyUp = this._onKeyUp.bind(this);
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ _onKeyDown: (Object) => void;
|
|
28
|
+
|
|
29
|
+ /**
|
|
30
|
+ * Handles 'Enter' key on the button to trigger onClick for accessibility.
|
|
31
|
+ *
|
|
32
|
+ * @param {Object} event - The key event.
|
|
33
|
+ * @private
|
|
34
|
+ * @returns {void}
|
|
35
|
+ */
|
|
36
|
+ _onKeyDown(event) {
|
|
37
|
+ // If the event coming to the dialog has been subject to preventDefault
|
|
38
|
+ // we don't handle it here.
|
|
39
|
+ if (event.defaultPrevented) {
|
|
40
|
+ return;
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ if (event.key === 'Enter') {
|
|
44
|
+ event.preventDefault();
|
|
45
|
+ event.stopPropagation();
|
|
46
|
+ this.props.onClick();
|
|
47
|
+ } else if (event.key === ' ') {
|
|
48
|
+ // Space triggers button onKeyUp but we need to prevent PTT here
|
|
49
|
+ event.preventDefault();
|
|
50
|
+ event.stopPropagation();
|
|
51
|
+ }
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ _onKeyUp: (Object) => void;
|
|
55
|
+
|
|
56
|
+ /**
|
|
57
|
+ * Handles ' ' (Space) key on the button to trigger onClick for
|
|
58
|
+ * accessibility.
|
|
59
|
+ *
|
|
60
|
+ * @param {Object} event - The key event.
|
|
61
|
+ * @private
|
|
62
|
+ * @returns {void}
|
|
63
|
+ */
|
|
64
|
+ _onKeyUp(event) {
|
|
65
|
+ // If the event coming to the dialog has been subject to preventDefault
|
|
66
|
+ // we don't handle it here.
|
|
67
|
+ if (event.defaultPrevented) {
|
|
68
|
+ return;
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ if (event.key === ' ') {
|
|
72
|
+ event.preventDefault();
|
|
73
|
+ event.stopPropagation();
|
|
74
|
+ this.props.onClick();
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+
|
15
|
78
|
/**
|
16
|
79
|
* Handles rendering of the actual item. If the label is being shown, which
|
17
|
80
|
* is controlled with the `showLabel` prop, the item is rendered for its
|
|
@@ -27,14 +90,22 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
|
27
|
90
|
elementAfter,
|
28
|
91
|
onClick,
|
29
|
92
|
showLabel,
|
30
|
|
- tooltipPosition
|
|
93
|
+ tooltipPosition,
|
|
94
|
+ toggled
|
31
|
95
|
} = this.props;
|
32
|
96
|
const className = showLabel ? 'overflow-menu-item' : 'toolbox-button';
|
33
|
97
|
const props = {
|
|
98
|
+ 'aria-pressed': toggled,
|
|
99
|
+ 'aria-disabled': disabled,
|
34
|
100
|
'aria-label': this.accessibilityLabel,
|
35
|
101
|
className: className + (disabled ? ' disabled' : ''),
|
36
|
|
- onClick: disabled ? undefined : onClick
|
|
102
|
+ onClick: disabled ? undefined : onClick,
|
|
103
|
+ onKeyDown: this._onKeyDown,
|
|
104
|
+ onKeyUp: this._onKeyUp,
|
|
105
|
+ tabIndex: 0,
|
|
106
|
+ role: 'button'
|
37
|
107
|
};
|
|
108
|
+
|
38
|
109
|
const elementType = showLabel ? 'li' : 'div';
|
39
|
110
|
const useTooltip = this.tooltip && this.tooltip.length > 0;
|
40
|
111
|
let children = (
|