feat(dropdown): Add additional field for setting an optional reference (like in TreeView)

This commit is contained in:
Andreas Bieber 2020-09-17 13:14:05 +02:00
parent 6e9f09aec1
commit 8bd1023ddc
1 changed files with 14 additions and 2 deletions

View File

@ -9,8 +9,9 @@ import (
// DropDownOption is one option that can be selected in a drop-down primitive.
type DropDownOption struct {
text string // The text to be displayed in the drop-down.
selected func(index int, option *DropDownOption) // The (optional) callback for when this option was selected.
text string // The text to be displayed in the drop-down.
selected func(index int, option *DropDownOption) // The (optional) callback for when this option was selected.
reference interface{} // An optional reference object.
}
func NewDropDownOption(text string) *DropDownOption {
@ -34,6 +35,17 @@ func (d *DropDownOption) SetSelectedFunc(handler func(index int, option *DropDow
return d
}
// GetReference returns the reference object of this dropdown option.
func (d *DropDownOption) GetReference() interface{} {
return d.reference
}
// SetReference allows you to store a reference of any type in this option.
func (d *DropDownOption) SetReference(reference interface{}) *DropDownOption {
d.reference = reference
return d
}
// SetChangedFunc sets a handler which is called when the user changes the
// drop-down's option. This handler will be called in addition and prior to
// an option's optional individual handler. The handler is provided with the