name the pay to wallet chooser and let the keyboard browse it before choosing
What changed, and why it matters
This commit improves the accessibility and keyboard behavior of the 'Pay to' wallet chooser in Sparrow Wallet. It lets users browse the list of wallets with arrow keys and only selects a wallet when they press Enter, Space, or click it. It also hides decorative wallet icons from screen readers and gives the chooser a readable label. There is no security-relevant change here.
No security action required. This is a usability/accessibility improvement. Review as normal UI code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the openWallets ComboBox in PaymentController so that value selection is deferred until the dropdown closes, and selection is only committed on Enter, Space, or mouse press. It adds keyboard event filters to ComboBoxTextField to open the dropdown with the Down arrow and return focus after closing. It also marks WalletIcon and decorative glyphs as accessibility-decorative (AccessibleRole.NODE, empty children) and adds accessibleText to the openWallets ComboBox in payment.fxml. No cryptographic, validation, or trust-boundary logic is modified.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/ComboBoxTextField.javasrc/main/java/com/sparrowwallet/sparrow/control/WalletIcon.javasrc/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.javasrc/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxmlInspect captured patch +141 / −30
### src/main/java/com/sparrowwallet/sparrow/control/ComboBoxTextField.java
@@ -6,10 +6,13 @@
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
+import javafx.scene.control.ComboBoxBase;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.input.Clipboard;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import org.controlsfx.control.textfield.CustomTextField;
@@ -32,6 +35,27 @@ public ComboBoxTextField() {
comboProperty.get().setVisible(!newValue);
}
});
+
+ //Down opens the list from the keyboard, as the button does with the mouse; the list takes the keys only while its combo has focus
+ addEventFilter(KeyEvent.KEY_PRESSED, event -> {
+ ComboBox<?> combo = comboProperty.get();
+ if(event.getCode() == KeyCode.DOWN && combo != null && combo.isVisible() && !combo.isDisabled() && !combo.isShowing()) {
+ combo.requestFocus();
+ combo.show();
+ event.consume();
+ }
+ });
+ comboProperty.addListener((observable, oldCombo, combo) -> {
+ if(combo != null) {
+ //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(() -> {
+ if(combo.getScene() != null && combo.getScene().getFocusOwner() == combo) {
+ requestFocus();
+ }
+ }));
+ }
+ });
}
private void setupComboButtonField(ObjectProperty<Node> rightProperty) {
@@ -53,8 +77,13 @@ private void setupComboButtonField(ObjectProperty<Node> rightProperty) {
if(!initialized) {
comboProperty.get().valueProperty().addListener((observable, oldValue, newValue) -> {
comboShowing = false;
- Platform.runLater(() -> comboProperty.get().getSelectionModel().clearSelection());
+ //While the list is open the value follows the highlighted item, which clearing would reset
+ if(!comboProperty.get().isShowing()) {
+ Platform.runLater(() -> comboProperty.get().getSelectionModel().clearSelection());
+ }
});
+ //A choice made while the list is open is cleared once it closes, so the same item can be chosen again
+ comboProperty.get().addEventHandler(ComboBoxBase.ON_HIDDEN, event -> Platform.runLater(() -> comboProperty.get().getSelectionModel().clearSelection()));
initialized = true;
}
}
### src/main/java/com/sparrowwallet/sparrow/control/WalletIcon.java
@@ -8,7 +8,10 @@
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;
@@ -53,6 +56,16 @@ 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/wallet/PaymentController.java
@@ -47,11 +47,18 @@
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.control.skin.ComboBoxListViewSkin;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
+import javafx.scene.input.MouseEvent;
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;
@@ -82,6 +89,9 @@ public class PaymentController extends WalletFormController implements Initializ
@FXML
private ComboBox<Wallet> openWallets;
+ private Wallet browsedWallet;
+ private boolean chooseBrowsedWallet;
+
@FXML
private ComboBoxTextField address;
@@ -303,34 +313,22 @@ public void setSendController(SendController sendController) {
public void initializeView() {
updateOpenWallets();
openWallets.prefWidthProperty().bind(address.widthProperty());
+ //While the list is open the value follows the highlighted wallet, so a wallet is only chosen once the list closes
openWallets.valueProperty().addListener((observable, oldValue, newValue) -> {
- if(newValue == payNymWallet) {
- PayNymDialog payNymDialog = new PayNymDialog(sendController.getWalletForm().getWalletId(), PayNymDialog.Operation.SEND);
- payNymDialog.initOwner(scanQrButton.getScene().getWindow());
- Optional<PayNym> optPayNym = payNymDialog.showAndWait();
- optPayNym.ifPresent(this::setPayNym);
- } else if(newValue == nfcCardWallet) {
- DeviceGetAddressDialog deviceGetAddressDialog = new DeviceGetAddressDialog(Collections.emptyList());
- deviceGetAddressDialog.initOwner(scanQrButton.getScene().getWindow());
- Optional<Address> optAddress = deviceGetAddressDialog.showAndWait();
- if(optAddress.isPresent()) {
- address.setText(optAddress.get().toString());
- label.requestFocus();
- }
+ if(!openWallets.isShowing()) {
+ selectOpenWallet(newValue);
} else if(newValue != null) {
- if(newValue.getPolicyType() == PolicyType.SINGLE_SP) {
- address.setText(newValue.getSilentPaymentScanAddress().getSilentPaymentAddress().getAddress());
- } else {
- List<Address> existingAddresses = getOtherAddresses();
- WalletNode freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE);
- Address freshAddress = freshNode.getAddress();
- while(existingAddresses.contains(freshAddress) || (freshNode.getLabel() != null && !freshNode.getLabel().isEmpty())) {
- freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE, freshNode);
- freshAddress = freshNode.getAddress();
- }
- address.setText(freshAddress.toString());
- }
- label.requestFocus();
+ browsedWallet = newValue;
+ }
+ });
+ //Only Enter, Space or a click on a wallet chooses it; closing the list any other way leaves the browsed wallet unchosen
+ openWallets.setOnHidden(event -> {
+ Wallet wallet = chooseBrowsedWallet ? browsedWallet : null;
+ browsedWallet = null;
+ chooseBrowsedWallet = false;
+ Platform.runLater(() -> openWallets.getSelectionModel().clearSelection());
+ if(wallet != null) {
+ selectOpenWallet(wallet);
}
});
openWallets.setCellFactory(c -> new ListCell<>() {
@@ -346,6 +344,32 @@ protected void updateItem(Wallet wallet, boolean empty) {
}
}
});
+ //Choosing a wallet fills the address and moves on to the label, so arrow keys open the list to browse rather than choosing the next wallet
+ openWallets.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
+ if((event.getCode() == KeyCode.UP || event.getCode() == KeyCode.DOWN) && !openWallets.isShowing()) {
+ openWallets.show();
+ event.consume();
+ }
+ });
+ openWallets.skinProperty().addListener((observable, oldSkin, skin) -> {
+ if(skin instanceof ComboBoxListViewSkin<?> listViewSkin) {
+ Node popupContent = listViewSkin.getPopupContent();
+ popupContent.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
+ if(event.getCode() == KeyCode.ENTER || event.getCode() == KeyCode.SPACE) {
+ chooseBrowsedWallet = true;
+ }
+ });
+ //Checked on the press, as the list closes in a release filter of its own that runs before one added here
+ popupContent.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
+ for(Node node = event.getPickResult().getIntersectedNode(); node != null && node != popupContent; node = node.getParent()) {
+ if(node instanceof ListCell<?> cell) {
+ chooseBrowsedWallet = !cell.isEmpty();
+ break;
+ }
+ }
+ });
+ }
+ });
openWallets.setOnShowing(event -> {
if(!openWallets.getItems().contains(nfcCardWallet) && CardApi.isReaderAvailable()) {
openWallets.getItems().add(nfcCardWallet);
@@ -510,13 +534,44 @@ private void updateOpenWallets(Collection<Wallet> wallets) {
openWallets.setItems(FXCollections.observableList(openWalletList));
}
+ private void selectOpenWallet(Wallet newValue) {
+ if(newValue == payNymWallet) {
+ PayNymDialog payNymDialog = new PayNymDialog(sendController.getWalletForm().getWalletId(), PayNymDialog.Operation.SEND);
+ payNymDialog.initOwner(scanQrButton.getScene().getWindow());
+ Optional<PayNym> optPayNym = payNymDialog.showAndWait();
+ optPayNym.ifPresent(this::setPayNym);
+ } else if(newValue == nfcCardWallet) {
+ DeviceGetAddressDialog deviceGetAddressDialog = new DeviceGetAddressDialog(Collections.emptyList());
+ deviceGetAddressDialog.initOwner(scanQrButton.getScene().getWindow());
+ Optional<Address> optAddress = deviceGetAddressDialog.showAndWait();
+ if(optAddress.isPresent()) {
+ address.setText(optAddress.get().toString());
+ label.requestFocus();
+ }
+ } else if(newValue != null) {
+ if(newValue.getPolicyType() == PolicyType.SINGLE_SP) {
+ address.setText(newValue.getSilentPaymentScanAddress().getSilentPaymentAddress().getAddress());
+ } else {
+ List<Address> existingAddresses = getOtherAddresses();
+ WalletNode freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE);
+ Address freshAddress = freshNode.getAddress();
+ while(existingAddresses.contains(freshAddress) || (freshNode.getLabel() != null && !freshNode.getLabel().isEmpty())) {
+ freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE, freshNode);
+ freshAddress = freshNode.getAddress();
+ }
+ address.setText(freshAddress.toString());
+ }
+ label.requestFocus();
+ }
+ }
+
private Node getOpenWalletIcon(Wallet wallet) {
if(wallet == payNymWallet) {
- return getPayNymGlyph();
+ return getDecorativeIcon(getPayNymGlyph());
}
if(wallet == nfcCardWallet) {
- return getNfcCardGlyph();
+ return getDecorativeIcon(getNfcCardGlyph());
}
Wallet masterWallet = wallet.isMasterWallet() ? wallet : wallet.getMasterWallet();
@@ -528,6 +583,20 @@ 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;
### src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml
@@ -32,7 +32,7 @@
<Fieldset inputGrow="ALWAYS">
<Field text="Pay to:">
<StackPane>
- <ComboBox fx:id="openWallets" />
+ <ComboBox fx:id="openWallets" accessibleText="Choose a wallet to pay to" />
<ComboBoxTextField fx:id="address" styleClass="address-text-field" comboProperty="$openWallets">
<tooltip>
<Tooltip text="Address, payment code or bitcoin: URI"/>Why this scored 15/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.