Reset#
func (typeahead *MenuTypeahead) Reset()Reset forgets the session, as closing the list does.
API 文档由 Go 源码生成,内容为英文。
type MenuTypeahead struct {
// contains filtered or unexported fields
}MenuTypeahead is caller-owned keyboard text matching for a menu or a list, Base UI's typeahead. Its zero value starts a new session; feed it one printable key at a time and it returns the row the query reaches. Time comes from the caller as it does for TooltipDelays, so nothing here schedules work.
var typeahead MenuTypeahead // reset it when the list opens
if id, ok := typeahead.Type(event.Text, now, scroll, event.Target); ok {
return ui.EventResult{Handled: true, Repaint: true, Focus: id, FocusVisible: true}
}Space is part of a query only while a session is running, so Type returns false for a lone Space and the caller can use it to activate the focused row, as Base UI does. A query that matches nothing ends the session.
Reset#func (typeahead *MenuTypeahead) Reset()Reset forgets the session, as closing the list does.
Type#func (typeahead *MenuTypeahead) Type(text string, now time.Time, scroll *MenuScroll, from ui.ID) (ui.ID, bool)Type feeds one printable key's text to the session and returns the row the query now reaches. now is the caller's clock. from is the row the keyboard was on when the session began (zero when none was), so a new query starts after it; a repeated first letter continues after the previous match, which is how Base UI cycles through rows that share an initial. It reports false when the key is not typeahead (a lone or trailing Space, a multi-rune key, or no match), and leaves the session reset.
TypeItems#func (typeahead *MenuTypeahead) TypeItems(text string, now time.Time, items []MenuTypeaheadItem, from ui.ID) (ui.ID, bool)TypeItems is Type for a list that is not painted in a MenuScroll, such as a closed select trigger: it matches the same way and returns the option's ID so the caller can commit it.
Typing#func (typeahead *MenuTypeahead) Typing(now time.Time) boolTyping reports whether a session is running at now, so the caller can tell a Space that continues a query from one that activates the focused row.