Skip to content

Commit

Permalink
#6877 Mobile: Do not use min size for mobiles
Browse files Browse the repository at this point in the history
Fixes #6877
  • Loading branch information
novikov82 committed Sep 7, 2023
1 parent 919b6eb commit 5e32dbd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class Question extends SurveyElement<Question>
protected setIsMobile(val: boolean) { }

@property({ defaultValue: false, onSet: (val: boolean, target: Question) => {
target.renderMinWidth = !val;
target.setIsMobile(val);
} }) isMobile: boolean;
@property() forceIsInputReadOnly: boolean;
Expand Down
4 changes: 3 additions & 1 deletion src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,16 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
}

@property({ defaultValue: true }) allowRootStyle: boolean;
@property({ defaultValue: true }) renderMinWidth: boolean;

get rootStyle() {
var style: { [index: string]: any } = {};
if (this.allowRootStyle && this.renderWidth) {
// style["width"] = this.renderWidth;
style["flexGrow"] = 1;
style["flexShrink"] = 1;
style["flexBasis"] = this.renderWidth;
style["minWidth"] = this.minWidth;
style["minWidth"] = this.renderMinWidth ? this.minWidth : "";
style["maxWidth"] = this.maxWidth;
}
return style;
Expand Down
27 changes: 27 additions & 0 deletions tests/surveyElementTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ QUnit.test("allowRootStyle", function (assert) {
survey.css = defaultV2Css;
assert.deepEqual(q1.rootStyle, {});
});
QUnit.test("rootStyle on mobile", function (assert) {
StylesManager.applyTheme("default");
const survey = new SurveyModel({
elements: [{
type: "text",
name: "q1"
}]
});
const q1 = survey.getQuestionByName("q1");
assert.ok(q1.renderMinWidth);
assert.deepEqual(q1.rootStyle, {
"flexBasis": "100%",
"flexGrow": 1,
"flexShrink": 1,
"maxWidth": "100%",
"minWidth": "300px",
});
survey.setIsMobile(true);
assert.notOk(q1.renderMinWidth);
assert.deepEqual(q1.rootStyle, {
"flexBasis": "100%",
"flexGrow": 1,
"flexShrink": 1,
"maxWidth": "100%",
"minWidth": ""
});
});
QUnit.test("question.errorLocation", function (assert) {
const survey = new SurveyModel({
elements: [
Expand Down

0 comments on commit 5e32dbd

Please sign in to comment.