Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eclipse-scout-core/src/form/fields/FormFieldLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ export class FormFieldLayout extends AbstractLayout {
prefSizeField = htmlField.prefSize(options)
.add(fieldMargins);
} else {
prefSizeField = graphics.prefSize(formField.$fieldContainer, options)
.add(fieldMargins);
prefSizeField = this._getPrefFieldSize(formField, options, fieldMargins);
}
}

Expand Down Expand Up @@ -381,4 +380,9 @@ export class FormFieldLayout extends AbstractLayout {
}
return this.formField.labelWidthInPixel;
}

protected _getPrefFieldSize(formField: FormField, options?: HtmlCompPrefSizeOptions, fieldMargins?: Insets) {
return graphics.prefSize(formField.$fieldContainer, options)
.add(fieldMargins);
}
}
8 changes: 8 additions & 0 deletions eclipse-scout-core/src/form/fields/stringfield/StringField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class StringField extends BasicField<string> implements StringFieldModel
trimText: boolean;
wrapText: boolean;
mouseClicked: boolean;
fitText: boolean;
protected _selectionChangingActionHandler: (event: JQuery.TriggeredEvent) => void;

constructor() {
Expand All @@ -53,6 +54,7 @@ export class StringField extends BasicField<string> implements StringFieldModel
this.spellCheckEnabled = false;
this.trimText = true;
this.wrapText = false;
this.fitText = false;

this._selectionChangingActionHandler = this._onSelectionChangingAction.bind(this);
}
Expand Down Expand Up @@ -151,6 +153,9 @@ export class StringField extends BasicField<string> implements StringFieldModel
// Restore obfuscated display text.
this.$field.val(this.displayText);
}
if (this.multilineText && this.fitText) {
this. revalidateLayoutTree();
}
}

protected _onMouseWheel(event: JQueryWheelEvent) {
Expand Down Expand Up @@ -470,6 +475,9 @@ export class StringField extends BasicField<string> implements StringFieldModel
} else if (event.type === 'keydown') {
// Use set timeout to let the cursor move to the target position
setTimeout(this._updateSelection.bind(this));
if (this.multilineText && this.fitText) {
this. revalidateLayoutTree();
}
} else {
this._updateSelection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
import {FormFieldLayout, graphics, Rectangle, StringField} from '../../../index';
import {Dimension, FormField, FormFieldLayout, graphics, HtmlCompPrefSizeOptions, Insets, Rectangle, StringField} from '../../../index';

export class StringFieldLayout extends FormFieldLayout {

Expand All @@ -21,4 +21,19 @@ export class StringFieldLayout extends FormFieldLayout {
}
super._layoutClearIcon(formField, fieldBounds, right, top);
}

protected override _getPrefFieldSize(formField: FormField, options?: HtmlCompPrefSizeOptions, fieldMargins?: Insets): Dimension {
let prefSize = super._getPrefFieldSize(formField, options, fieldMargins);
if ((formField as StringField).fitText){
let height = formField.$field.outerHeight();
let width = formField.$field.outerWidth();
// set width to 0 to accurately measure scroll height
formField.$field.css('height', 0);
formField.$field.css('width', prefSize.width);
prefSize.height = formField.$field[0].scrollHeight;
formField.$field.css('height', height + 'px');
formField.$field.css('width', width + 'px');
}
return prefSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ export interface StringFieldModel extends BasicFieldModel<string> {
* Default is false.
*/
wrapText?: boolean;
/**
* Adjust the size of the field to the height of its content
*
* Default is false
*/
fitText?: boolean;
}