Skip to content

Commit

Permalink
Merge pull request #4112 from dweymouth/hyperlink-keyboard-ontapped
Browse files Browse the repository at this point in the history
Hyperlink: Invoke OnTapped callback when typing space bar while focused
  • Loading branch information
dweymouth authored Aug 1, 2023
2 parents deb688c + 8eb490c commit 0c031a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion widget/hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
13 changes: 13 additions & 0 deletions widget/hyperlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0c031a5

Please sign in to comment.