From 8eb490c59c1c06dd6190dc6c9dc7f7c2ea2fdad2 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 31 Jul 2023 16:27:55 -0700 Subject: [PATCH] invoke OnTapped callback when activating hyperlink with space bar --- widget/hyperlink.go | 2 +- widget/hyperlink_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/widget/hyperlink.go b/widget/hyperlink.go index 944b301d6b..6f424f50ff 100644 --- a/widget/hyperlink.go +++ b/widget/hyperlink.go @@ -172,7 +172,7 @@ func (hl *Hyperlink) TypedRune(rune) { // TypedKey is a hook called by the input handling logic on key events if this object is focused. func (hl *Hyperlink) TypedKey(ev *fyne.KeyEvent) { if ev.Name == fyne.KeySpace { - hl.openURL() + hl.Tapped(nil) } } diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 97310d0114..29dc6e31fb 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -93,6 +93,19 @@ func TestHyperlink_OnTapped(t *testing.T) { assert.Equal(t, 1, tapped) } +func TestHyperlink_KeyboardOnTapped(t *testing.T) { + tapped := 0 + link := &Hyperlink{Text: "Test"} + link.TypedKey(&fyne.KeyEvent{Name: fyne.KeySpace}) + assert.Equal(t, 0, tapped) + + link.OnTapped = func() { + tapped++ + } + link.TypedKey(&fyne.KeyEvent{Name: fyne.KeySpace}) + assert.Equal(t, 1, tapped) +} + func TestHyperlink_Resize(t *testing.T) { hyperlink := &Hyperlink{Text: "Test"} hyperlink.CreateRenderer()