hide decorative images from screen readers, announce the first list item, start the import dialog on its source and keep the list button in step
What changed, and why it matters
This commit improves accessibility for users relying on screen readers. It hides purely decorative icons and images so they aren't read aloud, makes the first item in dropdown lists announced when opened from the keyboard, and moves keyboard focus to the correct starting point in an import dialog. There is no security vulnerability or malicious change here.
No security action required. Treat as a normal accessibility/usability improvement. Reviewers may optionally verify that DecorativePane is applied consistently to other decorative icons in the codebase.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch is an accessibility/usability refactor. It introduces a new DecorativePane helper class that exposes AccessibleRole.NODE and an empty children list to screen readers, then replaces ad-hoc anonymous StackPane overrides and direct StackPane inheritance in DialogImage, WalletIcon, WalletModelImage, and PaymentController with this shared class. ComboBoxTextField is reworked to track whether the combo list was just hidden so the toggle button stays in sync, and to select the first item when the list is opened from the keyboard so assistive technologies announce it. KeystoreImportController now requests focus on the selected import source toggle rather than the dialog’s first button. No cryptographic, network, or input-validation logic is modified.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/ComboBoxTextField.javasrc/main/java/com/sparrowwallet/sparrow/control/DecorativePane.javasrc/main/java/com/sparrowwallet/sparrow/control/DialogImage.javasrc/main/java/com/sparrowwallet/sparrow/control/WalletIcon.javasrc/main/java/com/sparrowwallet/sparrow/control/WalletModelImage.javasrc/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportController.javasrc/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.javaInspect captured patch +65 / −53
### src/main/java/com/sparrowwallet/sparrow/control/ComboBoxTextField.java
@@ -27,8 +27,8 @@
public class ComboBoxTextField extends CustomTextField {
private final ObjectProperty<ComboBox<?>> comboProperty = new SimpleObjectProperty<>();
- private boolean initialized;
- private boolean comboShowing;
+ private boolean comboJustHidden;
+ private boolean hideOnRelease;
private Object browsedItem;
private boolean chooseBrowsedItem;
@@ -48,12 +48,17 @@ public ComboBoxTextField() {
ComboBox<?> combo = comboProperty.get();
if(event.getCode() == KeyCode.DOWN && combo != null && combo.isVisible() && !combo.isDisabled() && !combo.isShowing()) {
combo.requestFocus();
- combo.show();
+ showFromKeyboard(combo);
event.consume();
}
});
comboProperty.addListener((observable, oldCombo, combo) -> {
if(combo != null) {
+ //Set until the current event finishes, so the button can tell that its own press closed the list
+ combo.addEventHandler(ComboBoxBase.ON_HIDDEN, event -> {
+ comboJustHidden = true;
+ Platform.runLater(() -> comboJustHidden = false);
+ });
//Closing the list without a choice that moves focus elsewhere returns focus here from the combo behind this field.
//The scene's focus owner is checked as isFocused() is false while a dialog opened by the choice is in front.
combo.addEventHandler(ComboBoxBase.ON_HIDDEN, event -> Platform.runLater(() -> {
@@ -71,21 +76,22 @@ private void setupComboButtonField(ObjectProperty<Node> rightProperty) {
StackPane showComboButtonPane = new StackPane(showComboButton);
showComboButtonPane.getStyleClass().addAll("combo-button"); //$NON-NLS-1$
showComboButtonPane.setCursor(Cursor.DEFAULT);
+ //The button opens a closed list and closes an open one, however it was opened or last closed. A press while the list is open
+ //closes it before the button sees the press, so whether it was open is taken from the press.
+ showComboButtonPane.setOnMousePressed(e -> {
+ ComboBox<?> combo = comboProperty.get();
+ hideOnRelease = combo != null && (combo.isShowing() || comboJustHidden);
+ });
showComboButtonPane.setOnMouseReleased(e -> {
- if(comboProperty.isNotNull().get()) {
- if(comboShowing) {
- comboProperty.get().hide();
+ ComboBox<?> combo = comboProperty.get();
+ if(combo != null) {
+ if(hideOnRelease) {
+ combo.hide();
} else {
- comboProperty.get().show();
- }
-
- comboShowing = !comboShowing;
-
- if(!initialized) {
- comboProperty.get().valueProperty().addListener((observable, oldValue, newValue) -> comboShowing = false);
- initialized = true;
+ combo.show();
}
}
+ hideOnRelease = false;
});
rightProperty.set(showComboButtonPane);
@@ -121,7 +127,7 @@ public <T> void setOnChoose(Consumer<T> onChoose) {
//Arrow keys on the closed combo open the list rather than choosing the next item
combo.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if((event.getCode() == KeyCode.UP || event.getCode() == KeyCode.DOWN) && !combo.isShowing()) {
- combo.show();
+ showFromKeyboard(combo);
event.consume();
}
});
@@ -150,6 +156,14 @@ public <T> void setOnChoose(Consumer<T> onChoose) {
combo.skinProperty().addListener((observable, oldSkin, skin) -> addChooseFilters.accept(skin));
}
+ //The first item is highlighted as the list opens, so it is announced and the next arrow moves on from it; highlighting only browses
+ private static void showFromKeyboard(ComboBox<?> combo) {
+ combo.show();
+ if(combo.getSelectionModel().isEmpty()) {
+ combo.getSelectionModel().selectFirst();
+ }
+ }
+
public ComboBox<?> getComboProperty() {
return comboProperty.get();
}
### src/main/java/com/sparrowwallet/sparrow/control/DecorativePane.java
@@ -0,0 +1,26 @@
+package com.sparrowwallet.sparrow.control;
+
+import javafx.collections.FXCollections;
+import javafx.scene.AccessibleAttribute;
+import javafx.scene.AccessibleRole;
+import javafx.scene.Node;
+import javafx.scene.layout.StackPane;
+
+/**
+ * Stack pane for an icon or image that decorates a name or title shown beside it. It is hidden from screen readers, which would
+ * otherwise read it as an unnamed image or, for a glyph, as empty text.
+ */
+public class DecorativePane extends StackPane {
+ public DecorativePane(Node... children) {
+ super(children);
+ }
+
+ @Override
+ public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
+ return switch(attribute) {
+ case ROLE -> AccessibleRole.NODE;
+ case CHILDREN -> FXCollections.emptyObservableList();
+ default -> super.queryAccessibleAttribute(attribute, parameters);
+ };
+ }
+}
### src/main/java/com/sparrowwallet/sparrow/control/DialogImage.java
@@ -4,7 +4,6 @@
import javafx.beans.NamedArg;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
-import javafx.scene.layout.StackPane;
import org.girod.javafx.svgimage.SVGImage;
import org.girod.javafx.svgimage.SVGLoader;
import org.slf4j.Logger;
@@ -13,7 +12,7 @@
import java.net.URL;
import java.util.Locale;
-public class DialogImage extends StackPane {
+public class DialogImage extends DecorativePane {
private static final Logger log = LoggerFactory.getLogger(DialogImage.class);
public static final int WIDTH = 50;
### src/main/java/com/sparrowwallet/sparrow/control/WalletIcon.java
@@ -8,10 +8,7 @@
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
-import javafx.collections.FXCollections;
import javafx.geometry.Pos;
-import javafx.scene.AccessibleAttribute;
-import javafx.scene.AccessibleRole;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.ImagePattern;
@@ -27,7 +24,7 @@
import java.net.URLConnection;
import java.net.URLStreamHandler;
-public class WalletIcon extends StackPane {
+public class WalletIcon extends DecorativePane {
public static final String PROTOCOL = "walleticon";
private static final String QUERY = "icon";
public static final int WIDTH = 15;
@@ -56,16 +53,6 @@ public WalletIcon(Storage storage, Wallet wallet, Keystore keystore, Glyph fallb
walletProperty.set(wallet);
}
- @Override
- public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
- //Decorative next to the wallet or keystore name, and its glyphs read as empty text
- return switch(attribute) {
- case ROLE -> AccessibleRole.NODE;
- case CHILDREN -> FXCollections.emptyObservableList();
- default -> super.queryAccessibleAttribute(attribute, parameters);
- };
- }
-
public void refresh() {
Wallet wallet = getWallet();
### src/main/java/com/sparrowwallet/sparrow/control/WalletModelImage.java
@@ -5,15 +5,14 @@
import javafx.beans.NamedArg;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
-import javafx.scene.layout.StackPane;
import org.girod.javafx.svgimage.SVGImage;
import org.girod.javafx.svgimage.SVGLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
-public class WalletModelImage extends StackPane {
+public class WalletModelImage extends DecorativePane {
private static final Logger log = LoggerFactory.getLogger(WalletModelImage.class);
public static final int WIDTH = 50;
### src/main/java/com/sparrowwallet/sparrow/keystoreimport/KeystoreImportController.java
@@ -64,7 +64,11 @@ public void initializeView(Wallet wallet) {
public void selectSource(KeystoreSource keystoreSource, boolean required) {
for(Toggle toggle : importMenu.getToggles()) {
if(toggle.getUserData().equals(keystoreSource)) {
- Platform.runLater(() -> importMenu.selectToggle(toggle));
+ //Focus starts on the chosen source rather than the dialog's first button
+ Platform.runLater(() -> {
+ importMenu.selectToggle(toggle);
+ ((ToggleButton)toggle).requestFocus();
+ });
} else if(required) {
((ToggleButton)toggle).setDisable(true);
}
### src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java
@@ -47,14 +47,11 @@
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
-import javafx.scene.AccessibleAttribute;
-import javafx.scene.AccessibleRole;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.HBox;
-import javafx.scene.layout.StackPane;
import org.controlsfx.glyphfont.Glyph;
import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.ValidationSupport;
@@ -517,11 +514,11 @@ private void selectOpenWallet(Wallet newValue) {
private Node getOpenWalletIcon(Wallet wallet) {
if(wallet == payNymWallet) {
- return getDecorativeIcon(getPayNymGlyph());
+ return new DecorativePane(getPayNymGlyph());
}
if(wallet == nfcCardWallet) {
- return getDecorativeIcon(getNfcCardGlyph());
+ return new DecorativePane(getNfcCardGlyph());
}
Wallet masterWallet = wallet.isMasterWallet() ? wallet : wallet.getMasterWallet();
@@ -533,20 +530,6 @@ private Node getOpenWalletIcon(Wallet wallet) {
return null;
}
- //Hidden from screen readers, as the glyph reads as empty text before the name it decorates
- private static Node getDecorativeIcon(Node glyph) {
- return new StackPane(glyph) {
- @Override
- public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
- return switch(attribute) {
- case ROLE -> AccessibleRole.NODE;
- case CHILDREN -> FXCollections.emptyObservableList();
- default -> super.queryAccessibleAttribute(attribute, parameters);
- };
- }
- };
- }
-
private void addValidation(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.