|
@@ -12,6 +12,41 @@ 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
|
+ }
|
|
25
|
+
|
|
26
|
+ _onKeyDown: (Object) => void;
|
|
27
|
+
|
|
28
|
+ /**
|
|
29
|
+ * Handles 'Enter' key on the button to trigger onClick for accessibility.
|
|
30
|
+ * We should be handling Space onKeyUp but it conflicts with PTT.
|
|
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
|
+ }
|
|
48
|
+ }
|
|
49
|
+
|
15
|
50
|
/**
|
16
|
51
|
* Handles rendering of the actual item. If the label is being shown, which
|
17
|
52
|
* is controlled with the `showLabel` prop, the item is rendered for its
|
|
@@ -27,14 +62,21 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
|
27
|
62
|
elementAfter,
|
28
|
63
|
onClick,
|
29
|
64
|
showLabel,
|
30
|
|
- tooltipPosition
|
|
65
|
+ tooltipPosition,
|
|
66
|
+ toggled
|
31
|
67
|
} = this.props;
|
32
|
68
|
const className = showLabel ? 'overflow-menu-item' : 'toolbox-button';
|
33
|
69
|
const props = {
|
|
70
|
+ 'aria-pressed': toggled,
|
|
71
|
+ 'aria-disabled': disabled,
|
34
|
72
|
'aria-label': this.accessibilityLabel,
|
35
|
73
|
className: className + (disabled ? ' disabled' : ''),
|
36
|
|
- onClick: disabled ? undefined : onClick
|
|
74
|
+ onClick: disabled ? undefined : onClick,
|
|
75
|
+ onKeyDown: this._onKeyDown,
|
|
76
|
+ tabIndex: 0,
|
|
77
|
+ role: 'button'
|
37
|
78
|
};
|
|
79
|
+
|
38
|
80
|
const elementType = showLabel ? 'li' : 'div';
|
39
|
81
|
const useTooltip = this.tooltip && this.tooltip.length > 0;
|
40
|
82
|
let children = (
|