mirror of https://github.com/mum4k/termdash.git
Merge pull request #282 from mum4k/243-textinput_exclusive_keyboard
Textinput can request keyboard exclusively.
This commit is contained in:
commit
82e52ead85
|
@ -54,6 +54,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- the `button` widget allows specifying separate fill color values for each of
|
||||
its main states (up, focused and up, down).
|
||||
|
||||
#### Updates to the `textinput` widget
|
||||
|
||||
- the `textinput` widget can now be configured to request keyboard events
|
||||
exclusively when focused.
|
||||
|
||||
## [0.13.0] - 17-Nov-2020
|
||||
|
||||
### Added
|
||||
|
|
|
@ -62,6 +62,7 @@ type options struct {
|
|||
filter FilterFn
|
||||
onSubmit SubmitFn
|
||||
clearOnSubmit bool
|
||||
exclusiveKeyboardOnFocus bool
|
||||
}
|
||||
|
||||
// validate validates the provided options.
|
||||
|
@ -263,3 +264,11 @@ func ClearOnSubmit() Option {
|
|||
opts.clearOnSubmit = true
|
||||
})
|
||||
}
|
||||
|
||||
// ExclusiveKeyboardOnFocus when set ensures that when this widget is focused,
|
||||
// no other widget receives any keyboard events.
|
||||
func ExclusiveKeyboardOnFocus() Option {
|
||||
return option(func(opts *options) {
|
||||
opts.exclusiveKeyboardOnFocus = true
|
||||
})
|
||||
}
|
||||
|
|
|
@ -328,6 +328,7 @@ func (ti *TextInput) Options() widgetapi.Options {
|
|||
},
|
||||
WantKeyboard: widgetapi.KeyScopeFocused,
|
||||
WantMouse: widgetapi.MouseScopeWidget,
|
||||
ExclusiveKeyboardOnFocus: ti.opts.exclusiveKeyboardOnFocus,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1704,6 +1704,19 @@ func TestOptions(t *testing.T) {
|
|||
WantMouse: widgetapi.MouseScopeWidget,
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "requests ExclusiveKeyboardOnFocus",
|
||||
opts: []Option{
|
||||
ExclusiveKeyboardOnFocus(),
|
||||
},
|
||||
want: widgetapi.Options{
|
||||
MinimumSize: image.Point{4, 1},
|
||||
MaximumSize: image.Point{0, 1},
|
||||
WantKeyboard: widgetapi.KeyScopeFocused,
|
||||
WantMouse: widgetapi.MouseScopeWidget,
|
||||
ExclusiveKeyboardOnFocus: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
|
Loading…
Reference in New Issue