Skip to content

Commit

Permalink
#5801 Add hidden title for questions in design mode
Browse files Browse the repository at this point in the history
Fixes #5801
  • Loading branch information
novikov82 committed Aug 20, 2024
1 parent 727b10a commit 54d3e56
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 33 deletions.
6 changes: 5 additions & 1 deletion packages/survey-creator-angular/src/question.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<sv-action-bar [model]="adorner.topActionContainer" [handleClick]="false"></sv-action-bar>
</div>
</div>

<div *ngIf="!model.hasTitle" [class]="adorner.cssCollapsedHiddenHeader">
<div [class]="adorner.cssCollapsedHiddenTitle">
<sv-ng-string [model]="model.locTitle"></sv-ng-string>
</div>
</div>
<ng-template [component]="{ name: componentName, data: componentData }"></ng-template>
<div *ngIf="adorner.isEmptyElement && !showPlaceholderComponent" class="svc-panel__placeholder_frame-wrapper">
<div class="svc-panel__placeholder_frame">
Expand Down
50 changes: 21 additions & 29 deletions packages/survey-creator-core/src/components/question.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ svc-question {
user-select: all;
pointer-events: all;
}

.sd-question__header--hidden {
padding-bottom: calcSize(1);
}
}

.svc-question__content > div,
Expand Down Expand Up @@ -528,18 +532,19 @@ svc-question,
& > *:not(.sd-element__header) {
display: none;
}
.sd-element__header {
& > *:not(.sd-element__title) {
display: none;
}
&.sd-panel__header--hidden {
display:block
}

.sd-element__title,
.sd-title.sd-element__title.sd-element__title--hidden {
display: block;
}
}
.sd-element__header {
& > *:not(.sd-element__title) {
display: none;
}
&.sd-panel__header--hidden,
&.sd-question__header--hidden {
display:block
}

.sd-element__title,
.sd-title.sd-element__title.sd-element__title--hidden {
display: block;
}
}
}
Expand Down Expand Up @@ -595,21 +600,6 @@ svc-question,
}
}

.svc-question__content--html,
.svc-question__content--image {
&.svc-question__content--empty {
padding-top: calcSize(5);
}
}
.svc-creator--mobile {
.svc-question__content--html,
.svc-question__content--image {
&.svc-question__content--empty {
padding-top: calcSize(3);
}
}
}

.sd-panel {
.svc-question__content--image:not(.svc-question__content--empty) {
padding-left: 1px;
Expand Down Expand Up @@ -863,7 +853,8 @@ svc-question,

.svc-question__content.svc-question__content--collapsed {
.sd-element--complex > .sd-element__header--location-top {
&.sd-panel__header--hidden {
&.sd-panel__header--hidden,
&.sd-question__header--hidden {
padding: 0;
}
}
Expand All @@ -876,7 +867,8 @@ svc-question,
.sd-element--complex > .sd-element__header--location-top {
padding-bottom: calc(0.5 * var(--sd-base-vertical-padding));
padding-top: 0;
&.sd-panel__header--hidden {
&.sd-panel__header--hidden,
&.sd-question__header--hidden {
padding-bottom: calcSize(1);
}
&:after {
Expand Down
9 changes: 8 additions & 1 deletion packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
QuestionPanelDynamicModel,
ListModel,
QuestionTextModel,
ActionContainer
ActionContainer,
PanelModel
} from "survey-core";
import { SurveyCreatorModel } from "../creator-base";
import { editorLocalization, getLocString } from "../editorLocalization";
Expand Down Expand Up @@ -188,6 +189,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
private get isMessagePanelVisible(): boolean {
return (this.element)?.getPropertyValue("isMessagePanelVisible");
}
get cssCollapsedHiddenHeader(): string {
return (this.element as PanelModel | Question).cssHeader + " sd-question__header--hidden";
}
get cssCollapsedHiddenTitle(): string {
return this.element.cssTitle + " sd-element__title--hidden";
}
public createBannerParams(): QuestionBannerParams {
return this.createCarryForwardParams() || this.createUsingRestfulParams() || this.createCustomMessagePanel();
}
Expand Down
7 changes: 7 additions & 0 deletions packages/survey-creator-knockout/src/adorners/question.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
</div>
</div>
<!-- /ko -->
<!-- ko ifnot: $data.element.hasTitle -->
<div data-bind="css: $data.cssCollapsedHiddenHeader">
<div data-bind="css: $data.cssCollapsedHiddenTitle">
<!-- ko template: { name: 'survey-string', data: $data.element.locTitle } --><!-- /ko -->
</div>
</div>
<!-- /ko -->
<!-- ko component: { name: 'sv-template-renderer', params: { componentData: null, templateData: templateData } } -->
<!-- /ko -->
<!-- ko if: koIsEmptyElement() && !$data.placeholderComponentData -->
Expand Down
19 changes: 17 additions & 2 deletions packages/survey-creator-react/src/adorners/Question.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { QuestionAdornerViewModel, toggleHovered } from "survey-creator-core";
import * as React from "react";
import { ReactDragEvent, ReactMouseEvent } from "../events";
import { Base, Question } from "survey-core";
import { Base, PanelModel, Question, SurveyElementCore } from "survey-core";
import {
SurveyActionBar,
ReactElementFactory,
SurveyQuestion,
attachKey2click,
SvgIcon,
Popup
Popup,
SurveyElementBase
} from "survey-react-ui";
import { CreatorModelElement } from "../ModelElement";

Expand Down Expand Up @@ -97,9 +98,23 @@ export class QuestionAdornerComponent extends CreatorModelElement<
if (!this.model.isBannerShowing) return null;
return ReactElementFactory.Instance.createElement("svc-question-banner", this.model.createBannerParams());
}

protected renderQuestionTitle(): JSX.Element {
if (this.model.element.hasTitle) return null;
const element = this.model.element as Question | PanelModel;
return (
<div className={this.model.cssCollapsedHiddenHeader} >
<div className={this.model.cssCollapsedHiddenTitle} >
{SurveyElementBase.renderLocString(element.locTitle, null, "q_title")}
</div>
</div>
);
}

protected renderElementContent(): JSX.Element {
return (
<>
{this.renderQuestionTitle()}
{this.props.element}
{this.renderElementPlaceholder()}
{this.renderCarryForwardBanner()}
Expand Down
5 changes: 5 additions & 0 deletions packages/survey-creator-vue/src/adorners/QuestionBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
></sv-action-bar>
</div>
</div>
<div v-if="!element.hasTitle" :class="model.cssCollapsedHiddenHeader">
<div :class="model.cssCollapsedHiddenTitle">
<survey-string :locString="element.locTitle"/>
</div>
</div>

<sv-template-renderer
:componentName="componentName"
Expand Down
55 changes: 55 additions & 0 deletions visualRegressionTests/tests/designer/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,61 @@ test("Question adorner - collapsed", async (t) => {
});
});

test("Question adorner - no title collapsed", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(1920, 1080);
const json = {
"logoPosition": "right",
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1",
"titleLocation": "hidden"
},
{
"type": "paneldynamic",
"name": "question4",
"titleLocation": "hidden"
},
{
"type": "html",
"name": "question2"
},
{
"type": "image",
"name": "question3",
"imageFit": "cover",
"imageHeight": "auto",
"imageWidth": "100%"
}
]
}
]
};
await ClientFunction(() => {
window["creator"].expandCollapseButtonVisibility = "onhover";
})();
await setJSON(json);
const qContent = Selector(".svc-question__content");
const qCollapseButton = Selector(".svc-question__content #collapse");
await t.click(qContent.nth(0), { offsetX: 10, offsetY: 10 });
await t.click(qCollapseButton.filterVisible());
await takeElementScreenshot("question-adorner-no-title-collapsed.png", qContent.nth(0), t, comparer);
await t.click(qContent.nth(1), { offsetX: 10, offsetY: 10 });
await t.click(qCollapseButton.filterVisible());
await takeElementScreenshot("panel-dynamic-adorner-no-title-collapsed.png", qContent.nth(1), t, comparer);
await t.click(qContent.nth(2), { offsetX: 10, offsetY: 10 });
await t.click(qCollapseButton.filterVisible());
await takeElementScreenshot("question-html-adorner-no-title-collapsed.png", qContent.nth(2), t, comparer);
await t.click(qContent.nth(3), { offsetX: 10, offsetY: 10 });
await t.click(qCollapseButton.filterVisible());
await takeElementScreenshot("question-image-adorner-no-title-collapsed.png", qContent.nth(3), t, comparer);
});
});

test("Page adorner - collapsed", async (t) => {
await wrapVisualTest(t, async (t, comparer) => {
await t.resizeWindow(1920, 1080);
Expand Down

0 comments on commit 54d3e56

Please sign in to comment.