@@ -30,57 +30,49 @@ import { Icon as NumberedListIcon } from "../../../../../../res/img/element-icon
30
30
import { Icon as CodeBlockIcon } from "../../../../../../res/img/element-icons/room/composer/code_block.svg" ;
31
31
import { Icon as IndentIcon } from "../../../../../../res/img/element-icons/room/composer/indent_increase.svg" ;
32
32
import { Icon as UnIndentIcon } from "../../../../../../res/img/element-icons/room/composer/indent_decrease.svg" ;
33
- import AccessibleTooltipButton from "../../../elements/AccessibleTooltipButton" ;
34
- import { Alignment } from "../../../elements/Tooltip" ;
35
- import { KeyboardShortcut } from "../../../settings/KeyboardShortcut" ;
36
- import { KeyCombo } from "../../../../../KeyBindingsManager" ;
37
33
import { _t } from "../../../../../languageHandler" ;
38
- import { ButtonEvent } from "../../../elements/AccessibleButton" ;
34
+ import AccessibleButton , { ButtonEvent } from "../../../elements/AccessibleButton" ;
39
35
import { openLinkModal } from "./LinkModal" ;
40
36
import { useComposerContext } from "../ComposerContext" ;
37
+ import { IS_MAC , Key } from "../../../../../Keyboard" ;
38
+ import { ALTERNATE_KEY_NAME } from "../../../../../accessibility/KeyboardShortcuts" ;
41
39
42
- interface TooltipProps {
43
- label : string ;
44
- keyCombo ?: KeyCombo ;
45
- }
46
-
47
- function Tooltip ( { label, keyCombo } : TooltipProps ) : JSX . Element {
48
- return (
49
- < div className = "mx_FormattingButtons_Tooltip" >
50
- { label }
51
- { keyCombo && (
52
- < KeyboardShortcut value = { keyCombo } className = "mx_FormattingButtons_Tooltip_KeyboardShortcut" />
53
- ) }
54
- </ div >
55
- ) ;
56
- }
57
-
58
- interface ButtonProps extends TooltipProps {
40
+ interface ButtonProps {
59
41
icon : ReactNode ;
60
42
actionState : ActionState ;
61
43
onClick : MouseEventHandler < HTMLButtonElement > ;
44
+ label : string ;
45
+ shortcut ?: string ;
62
46
}
63
47
64
- function Button ( { label, keyCombo , onClick, actionState, icon } : ButtonProps ) : JSX . Element {
48
+ function Button ( { label, shortcut , onClick, actionState, icon } : ButtonProps ) : JSX . Element {
65
49
return (
66
- < AccessibleTooltipButton
50
+ < AccessibleButton
67
51
element = "button"
68
52
onClick = { onClick as ( e : ButtonEvent ) => void }
69
- title = { label }
53
+ aria-label = { label }
70
54
className = { classNames ( "mx_FormattingButtons_Button" , {
71
55
mx_FormattingButtons_active : actionState === "reversed" ,
72
56
mx_FormattingButtons_Button_hover : actionState === "enabled" ,
73
57
mx_FormattingButtons_disabled : actionState === "disabled" ,
74
58
} ) }
75
- tooltip = { keyCombo && < Tooltip label = { label } keyCombo = { keyCombo } /> }
76
- forceHide = { actionState === "disabled" }
77
- alignment = { Alignment . Top }
59
+ title = { actionState === "disabled" ? undefined : label }
60
+ caption = { shortcut }
61
+ placement = "top"
78
62
>
79
63
{ icon }
80
- </ AccessibleTooltipButton >
64
+ </ AccessibleButton >
81
65
) ;
82
66
}
83
67
68
+ /**
69
+ * Get the shortcut string for a given key.
70
+ * @param key
71
+ */
72
+ function getShortcutFromKey ( key : string ) : string {
73
+ return ( IS_MAC ? "⌘" : _t ( ALTERNATE_KEY_NAME [ Key . CONTROL ] ) ) + "+" + key ;
74
+ }
75
+
84
76
interface FormattingButtonsProps {
85
77
composer : FormattingFunctions ;
86
78
actionStates : AllActionStates ;
@@ -94,21 +86,21 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP
94
86
< Button
95
87
actionState = { actionStates . bold }
96
88
label = { _t ( "composer|format_bold" ) }
97
- keyCombo = { { ctrlOrCmdKey : true , key : "b" } }
89
+ shortcut = { getShortcutFromKey ( "B" ) }
98
90
onClick = { ( ) => composer . bold ( ) }
99
91
icon = { < BoldIcon className = "mx_FormattingButtons_Icon" /> }
100
92
/>
101
93
< Button
102
94
actionState = { actionStates . italic }
103
95
label = { _t ( "composer|format_italic" ) }
104
- keyCombo = { { ctrlOrCmdKey : true , key : "i" } }
96
+ shortcut = { getShortcutFromKey ( "I" ) }
105
97
onClick = { ( ) => composer . italic ( ) }
106
98
icon = { < ItalicIcon className = "mx_FormattingButtons_Icon" /> }
107
99
/>
108
100
< Button
109
101
actionState = { actionStates . underline }
110
102
label = { _t ( "composer|format_underline" ) }
111
- keyCombo = { { ctrlOrCmdKey : true , key : "u" } }
103
+ shortcut = { getShortcutFromKey ( "U" ) }
112
104
onClick = { ( ) => composer . underline ( ) }
113
105
icon = { < UnderlineIcon className = "mx_FormattingButtons_Icon" /> }
114
106
/>
@@ -155,7 +147,7 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP
155
147
< Button
156
148
actionState = { actionStates . inlineCode }
157
149
label = { _t ( "composer|format_inline_code" ) }
158
- keyCombo = { { ctrlOrCmdKey : true , key : "e" } }
150
+ shortcut = { getShortcutFromKey ( "E" ) }
159
151
onClick = { ( ) => composer . inlineCode ( ) }
160
152
icon = { < InlineCodeIcon className = "mx_FormattingButtons_Icon" /> }
161
153
/>
0 commit comments