Skip to content

Commit

Permalink
Textinput can request keyboard exclusively.
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Dec 27, 2020
1 parent 4265242 commit 912de88
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions widgets/textinput/options.go
Expand Up @@ -59,9 +59,10 @@ type options struct {
placeHolder string
hideTextWith rune

filter FilterFn
onSubmit SubmitFn
clearOnSubmit bool
filter FilterFn
onSubmit SubmitFn
clearOnSubmit bool
exclusiveKeyboardOnFocus bool
}

// validate validates the provided options.
Expand Down Expand Up @@ -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
})
}
5 changes: 3 additions & 2 deletions widgets/textinput/textinput.go
Expand Up @@ -326,8 +326,9 @@ func (ti *TextInput) Options() widgetapi.Options {
maxWidth,
needHeight,
},
WantKeyboard: widgetapi.KeyScopeFocused,
WantMouse: widgetapi.MouseScopeWidget,
WantKeyboard: widgetapi.KeyScopeFocused,
WantMouse: widgetapi.MouseScopeWidget,
ExclusiveKeyboardOnFocus: ti.opts.exclusiveKeyboardOnFocus,
}
}

Expand Down
13 changes: 13 additions & 0 deletions widgets/textinput/textinput_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 912de88

Please sign in to comment.