From b15305d727890edcff2af6113fd8e0b7f260ee5e Mon Sep 17 00:00:00 2001 From: anoshenko Date: Sun, 7 May 2023 19:44:28 +0300 Subject: [PATCH] Changed FocusView function --- CHANGELOG.md | 1 + viewUtils.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9542c3..7fe4f7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Changed the main event listener format for "drop-down-event", "edit-text-changed", "color-changed", "number-changed", "date-changed", and "time-changed" events. Old format is "(, )", new format is "(, , )" +* Changed FocusView function * Bug fixing # v0.12.0 diff --git a/viewUtils.go b/viewUtils.go index 2c4600f..09ad5ca 100644 --- a/viewUtils.go +++ b/viewUtils.go @@ -830,9 +830,13 @@ func colorStyledProperty(view View, subviewID []string, tag string, inherit bool return Color(0) } -// FocusView sets focus on the specified View, if it can be focused. +// FocusView sets focus on the specified subview, if it can be focused. // The focused View is the View which will receive keyboard events by default. -func FocusView(view View) { +// If the second argument (subviewID) is not specified or it is "" then focus is set on the first argument (view) +func FocusView(view View, subviewID ...string) { + if len(subviewID) > 0 && subviewID[0] != "" { + view = ViewByID(view, subviewID[0]) + } if view != nil { view.Session().callFunc("focus", view.htmlID()) }