D3vugu-components/components/input/dropdown.go

47 lines
848 B
Go
Raw Normal View History

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)
}