mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 01:25:36 -05:00
Add ability to handle enter key propagation for input model components (#7524)
* Add ability to stop enter key propagation for input model components * Fix spacing * onInputEntered -> onEnterKeyPressed
This commit is contained in:
@@ -72,6 +72,17 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
|
||||
};
|
||||
if (this._inputContainer) {
|
||||
this._input = new InputBox(this._inputContainer.nativeElement, this.contextViewService, inputOptions);
|
||||
this.onkeydown(this._input.inputElement, (e: StandardKeyboardEvent) => {
|
||||
if (e.keyCode === KeyCode.Enter) {
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onEnterKeyPressed,
|
||||
args: this._input.value
|
||||
});
|
||||
if (this.stopEnterPropagation) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.registerInput(this._input, () => !this.multiline);
|
||||
}
|
||||
if (this._textareaContainer) {
|
||||
@@ -81,6 +92,15 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
|
||||
if (this.tryHandleKeyEvent(e)) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
if (e.keyCode === KeyCode.Enter) {
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onEnterKeyPressed,
|
||||
args: this._textAreaInput.value
|
||||
});
|
||||
if (this.stopEnterPropagation) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
}
|
||||
// Else assume that keybinding service handles routing this to a command
|
||||
});
|
||||
|
||||
@@ -308,4 +328,12 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
|
||||
public set required(newValue: boolean) {
|
||||
this.setPropertyFromUI<azdata.InputBoxProperties, boolean>((props, value) => props.required = value, newValue);
|
||||
}
|
||||
|
||||
public get stopEnterPropagation(): boolean {
|
||||
return this.getPropertyOrDefault<azdata.InputBoxProperties, boolean>((props) => props.stopEnterPropagation, false);
|
||||
}
|
||||
|
||||
public set stopEnterPropagation(newValue: boolean) {
|
||||
this.setPropertyFromUI<azdata.InputBoxProperties, boolean>((props, value) => props.stopEnterPropagation = value, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user