Skip to content

Commit c9f7544

Browse files
committed
Formatting toolbar buttons made more accessible
The formatting and media buttons that need to be announced as buttons are found and configured using the extension function that does the modification of it's accessibility properties.
1 parent d291c0d commit c9f7544

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.wordpress.aztec.R
3232
import org.wordpress.aztec.plugins.IMediaToolbarButton
3333
import org.wordpress.aztec.plugins.IToolbarButton
3434
import org.wordpress.aztec.source.SourceViewEditText
35+
import org.wordpress.aztec.util.convertToButtonStateForAccessibility
3536
import java.util.Arrays
3637
import java.util.ArrayList
3738
import java.util.Locale
@@ -407,6 +408,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
407408

408409
setAdvancedState()
409410
setupMediaToolbar()
411+
setupToolbarButtonsForAccessibility()
410412

411413
for (toolbarAction in ToolbarAction.values()) {
412414
val button = findViewById<ToggleButton>(toolbarAction.buttonId)
@@ -434,7 +436,33 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
434436
toolbarButtonPlugins.add(buttonPlugin)
435437

436438
val button = findViewById<ToggleButton>(buttonPlugin.action.buttonId)
437-
button.setOnClickListener { _: View -> buttonPlugin.toggle() }
439+
button.setOnClickListener { buttonPlugin.toggle() }
440+
441+
setupMediaButtonForAccessibility(buttonPlugin)
442+
}
443+
444+
private fun setupMediaButtonForAccessibility(buttonPlugin: IToolbarButton) {
445+
val button = findViewById<ToggleButton>(buttonPlugin.action.buttonId)
446+
447+
if (buttonPlugin is IMediaToolbarButton) {
448+
button.convertToButtonStateForAccessibility()
449+
}
450+
}
451+
452+
private fun setupToolbarButtonsForAccessibility() {
453+
val targetActions = listOf(ToolbarAction.ADD_MEDIA_EXPAND,
454+
ToolbarAction.ADD_MEDIA_COLLAPSE,
455+
ToolbarAction.HORIZONTAL_RULE,
456+
ToolbarAction.HEADING,
457+
ToolbarAction.LIST,
458+
ToolbarAction.LINK
459+
)
460+
461+
ToolbarAction.values().forEach { action ->
462+
if (targetActions.contains(action)) {
463+
findViewById<ToggleButton>(action.buttonId).convertToButtonStateForAccessibility()
464+
}
465+
}
438466
}
439467

440468
fun highlightActionButtons(toolbarActions: ArrayList<IToolbarAction>) {

0 commit comments

Comments
 (0)