Skip to content

Commit 5f6f8cc

Browse files
committed
Fix the bug on changing rightIndent property. Tells question to adjust it's padding correctly.
1 parent 3ae69f2 commit 5f6f8cc

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/knockout/koquestionbase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module Survey {
99
this.koVisible = ko.observable(this.question.visible);
1010
this.koRenderWidth = ko.observable(this.question.renderWidth);
1111
this.koErrors = ko.observableArray();
12-
this.koMarginLeft = ko.pureComputed(function () { return self.getIndentSize(self.question.indent); });
13-
this.koPaddingRight = ko.pureComputed(function () { return self.getIndentSize(self.question.rightIndent); });
12+
this.koMarginLeft = ko.pureComputed(function () { self.koRenderWidth(); return self.getIndentSize(self.question.indent); });
13+
this.koPaddingRight = ko.observable(self.getIndentSize(self.question.rightIndent));
1414
this.question["koVisible"] = this.koVisible;
1515
this.question["koRenderWidth"] = this.koRenderWidth;
1616
this.question["koErrors"] = this.koErrors;
@@ -22,6 +22,7 @@ module Survey {
2222
}
2323
protected onRenderWidthChanged() {
2424
this.koRenderWidth(this.question.renderWidth);
25+
this.koPaddingRight(this.getIndentSize(this.question.rightIndent));
2526
}
2627
private getIndentSize(indent: number): string {
2728
if (indent < 1) return "";

src/questionbase.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module Survey {
1616
private visibleIndexValue: number = -1;
1717
public width: string = "";
1818
private renderWidthValue: string = "";
19+
private rightIndentValue: number = 0;
1920
public indent: number = 0;
20-
public rightIndent: number = 0;
2121
focusCallback: () => void;
2222
renderWidthChangedCallback: () => void;
2323
rowVisibilityChangedCallback: () => void;
@@ -50,6 +50,12 @@ module Survey {
5050
this.renderWidthValue = val;
5151
this.fireCallback(this.renderWidthChangedCallback);
5252
}
53+
public get rightIndent(): number { return this.rightIndentValue; }
54+
public set rightIndent(val: number) {
55+
if (val == this.rightIndent) return;
56+
this.rightIndentValue = val;
57+
this.fireCallback(this.renderWidthChangedCallback);
58+
}
5359
public focus() {
5460
var el = document.getElementById(this.id);
5561
if (!el || !el.scrollIntoView) return;

src/react/reactquestion.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ class ReactSurveyQuestion extends React.Component<any, any> {
3232
this.questionBase = question;
3333
this.question = question instanceof Survey.Question ? question : null;
3434
var value = this.question ? this.question.value : null;
35-
this.state = { visible: this.questionBase.visible, value: value, error: 0 };
35+
this.state = { visible: this.questionBase.visible, value: value, error: 0, renderWidth: 0 };
36+
var self = this;
37+
if (this.questionBase) {
38+
this.questionBase.renderWidthChangedCallback = function () {
39+
self.state.renderWidth = self.state.renderWidth + 1;
40+
self.setState(self.state);
41+
}
42+
}
3643
}
3744
render(): JSX.Element {
3845
if (!this.questionBase || !this.creator) return null;

0 commit comments

Comments
 (0)