|
@@ -12,69 +12,6 @@ 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
|
|
-
|
78
|
15
|
/**
|
79
|
16
|
* Handles rendering of the actual item. If the label is being shown, which
|
80
|
17
|
* is controlled with the `showLabel` prop, the item is rendered for its
|
|
@@ -90,22 +27,14 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
|
90
|
27
|
elementAfter,
|
91
|
28
|
onClick,
|
92
|
29
|
showLabel,
|
93
|
|
- tooltipPosition,
|
94
|
|
- toggled
|
|
30
|
+ tooltipPosition
|
95
|
31
|
} = this.props;
|
96
|
32
|
const className = showLabel ? 'overflow-menu-item' : 'toolbox-button';
|
97
|
33
|
const props = {
|
98
|
|
- 'aria-pressed': toggled,
|
99
|
|
- 'aria-disabled': disabled,
|
100
|
34
|
'aria-label': this.accessibilityLabel,
|
101
|
35
|
className: className + (disabled ? ' disabled' : ''),
|
102
|
|
- onClick: disabled ? undefined : onClick,
|
103
|
|
- onKeyDown: this._onKeyDown,
|
104
|
|
- onKeyUp: this._onKeyUp,
|
105
|
|
- tabIndex: 0,
|
106
|
|
- role: 'button'
|
|
36
|
+ onClick: disabled ? undefined : onClick
|
107
|
37
|
};
|
108
|
|
-
|
109
|
38
|
const elementType = showLabel ? 'li' : 'div';
|
110
|
39
|
const useTooltip = this.tooltip && this.tooltip.length > 0;
|
111
|
40
|
let children = (
|