You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
848 B
Go

package input
import (
"github.com/vugu/vugu"
)
// Dropdown provides several options that the user can choose.
type Dropdown struct {
AttrMap vugu.AttrMap
Bind ValueBinder // Binds the current selected key to some variable.
BindList ListBinder // Binds the list content to some list provider.
}
func (c *Dropdown) currentKey() string {
if c.Bind == nil {
return ""
}
return c.Bind.StringValue()
}
func (c *Dropdown) isKeySelected(key string) bool {
if c.Bind == nil {
return false
}
return key == c.Bind.StringValue()
}
func (c *Dropdown) keyValuePairs() []ListKeyValuePair {
if c.BindList == nil {
return nil
}
return c.BindList.ListKeyValuePairs()
}
func (c *Dropdown) handleChange(event vugu.DOMEvent) {
if c.Bind == nil {
return
}
val := event.PropString("target", "value")
c.Bind.SetStringValue(val)
}