fix input box issues (#15587)

This commit is contained in:
Alan Ren
2021-05-27 09:35:59 -07:00
committed by GitHub
parent b75e688a7e
commit 3946cee33c
4 changed files with 30 additions and 0 deletions

View File

@@ -817,6 +817,13 @@ declare module 'azdata' {
Informational = 'Informational' Informational = 'Informational'
} }
export interface InputBoxProperties {
/**
* The maximum number of characters allowed in the input box.
*/
maxLength?: number;
}
export namespace workspace { export namespace workspace {
/** /**
* Creates and enters a workspace at the specified location * Creates and enters a workspace at the specified location

View File

@@ -93,6 +93,16 @@ export class InputBox extends vsInputBox {
public setHeight(value: string) { public setHeight(value: string) {
if (this._isTextAreaInput) { if (this._isTextAreaInput) {
this.inputElement.style.height = value; this.inputElement.style.height = value;
this.inputElement.style.whiteSpace = 'normal';
}
}
public setMaxLength(value: number | undefined) {
if (value === undefined) {
this.inputElement.removeAttribute('maxLength');
}
else {
this.inputElement.maxLength = value;
} }
} }

View File

@@ -1074,6 +1074,14 @@ class InputBoxWrapper extends ComponentWrapper implements azdata.InputBoxCompone
this.setProperty('validationErrorMessage', v); this.setProperty('validationErrorMessage', v);
} }
public get maxLength(): number | undefined {
return this.properties['maxLength'];
}
public set maxLength(v: number | undefined) {
this.setProperty('maxLength', v);
}
public get onTextChanged(): vscode.Event<any> { public get onTextChanged(): vscode.Event<any> {
let emitter = this._emitterMap.get(ComponentEventType.onDidChange); let emitter = this._emitterMap.get(ComponentEventType.onDidChange);
return emitter && emitter.event; return emitter && emitter.event;

View File

@@ -222,6 +222,7 @@ export default class InputBoxComponent extends ComponentBase<azdata.InputBoxProp
input.setAriaLabel(this.ariaLabel); input.setAriaLabel(this.ariaLabel);
input.setPlaceHolder(this.placeHolder); input.setPlaceHolder(this.placeHolder);
input.setEnabled(this.enabled); input.setEnabled(this.enabled);
input.setMaxLength(this.maxLength);
this.layoutInputBox(); this.layoutInputBox();
if (this.multiline) { if (this.multiline) {
if (isNumber(this.rows)) { if (isNumber(this.rows)) {
@@ -347,6 +348,10 @@ export default class InputBoxComponent extends ComponentBase<azdata.InputBoxProp
this.setPropertyFromUI<boolean>((props, value) => props.stopEnterPropagation = value, newValue); this.setPropertyFromUI<boolean>((props, value) => props.stopEnterPropagation = value, newValue);
} }
public get maxLength(): number | undefined {
return this.getPropertyOrDefault<number | undefined>((props) => props.maxLength, undefined);
}
public focus(): void { public focus(): void {
this.inputElement.focus(); this.inputElement.focus();
} }