Skip to content

Commit

Permalink
Merge pull request #5455 from andydotxyz/fix/5454
Browse files Browse the repository at this point in the history
Allow OnSelected of a tab to focus content
  • Loading branch information
andydotxyz authored Jan 24, 2025
2 parents e553897 + 747fc68 commit 03415ab
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 0 additions & 2 deletions container/apptabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,11 @@ func (t *AppTabs) RemoveIndex(index int) {
// Select sets the specified TabItem to be selected and its content visible.
func (t *AppTabs) Select(item *TabItem) {
selectItem(t, item)
t.Refresh()
}

// SelectIndex sets the TabItem at the specific index to be selected and its content visible.
func (t *AppTabs) SelectIndex(index int) {
selectIndex(t, index)
t.Refresh()
}

// SelectTab sets the specified TabItem to be selected and its content visible.
Expand Down
14 changes: 14 additions & 0 deletions container/apptabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ func TestAppTabs_Select(t *testing.T) {
assert.Equal(t, tab2, tabs.Selected())
}

func TestAppTabs_SelectFocus(t *testing.T) {
tab1 := &TabItem{Text: "Test1", Content: widget.NewEntry()}
tab2 := &TabItem{Text: "Test2", Content: widget.NewEntry()}
tabs := NewAppTabs(tab1, tab2)
w := test.NewTempWindow(t, tabs)

tabs.OnSelected = func(t *TabItem) {
w.Canvas().Focus(t.Content.(*widget.Entry))
}

tabs.Select(tab2)
assert.Equal(t, tab2.Content, w.Canvas().Focused())
}

func TestAppTabs_SelectIndex(t *testing.T) {
tabs := NewAppTabs(&TabItem{Text: "Test1", Content: widget.NewLabel("Test1")},
&TabItem{Text: "Test2", Content: widget.NewLabel("Test2")})
Expand Down
1 change: 0 additions & 1 deletion container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func (t *DocTabs) Select(item *TabItem) {
// SelectIndex sets the TabItem at the specific index to be selected and its content visible.
func (t *DocTabs) SelectIndex(index int) {
selectIndex(t, index)
t.Refresh()
}

// Selected returns the currently selected TabItem.
Expand Down
1 change: 1 addition & 0 deletions container/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func selectIndex(t baseTabs, index int) {

t.setTransitioning(true)
t.setSelected(index)
t.Refresh()

if f := t.onSelected(); f != nil {
// Notification of selected
Expand Down

0 comments on commit 03415ab

Please sign in to comment.