Skip to content

Commit

Permalink
#8129 - hover styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Novikov committed May 23, 2024
1 parent 0d8bfef commit 15cc176
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<div [class]="listModel.cssClasses.itemSeparator"></div>
</ng-container>
<div [class]="listModel.cssClasses.itemBody" [style.paddingInlineStart]="paddingLeft" [attr.title]="model.locTitle.calculatedText"
(mouseover)="listModel.onItemHover(model)">
(mouseover)="listModel.onItemHover(model)"
(mouseleave)="listModel.onItemLeave(model)">
<ng-template [component]="{ name: model.component || 'sv-list-item-content', data: { model: model, listModel: listModel } }"></ng-template>
</div>
</li>
Expand Down
1 change: 1 addition & 0 deletions packages/survey-vue3-ui/src/components/list/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
v-bind:class="model.cssClasses.itemBody"
:title="item.locTitle.calculatedText"
@mouseover="(e) => model.onItemHover(item)"
@mouseover="(e) => model.onItemLeave(item)"
>
<component :is="item.component || 'sv-list-item-content'" :item="item" :model="model">
</component>
Expand Down
7 changes: 5 additions & 2 deletions src/common-styles/sv-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
transition: background-color $transition-duration, color $transition-duration;
transition:
background-color $transition-duration,
color $transition-duration;
}

.sv-list__item.sv-list__item--focused:not(.sv-list__item--selected) {
Expand All @@ -80,6 +82,7 @@
outline: none;
}

.sv-list__item--hovered > .sv-list__item-body,
.sv-list__item-body:hover,
.sv-list__item-body:focus {
background-color: $background-dark;
Expand Down Expand Up @@ -251,4 +254,4 @@ li:focus .sv-list__item.sv-list__item--selected {

.sv-list__loading-indicator .sv-list__item-body {
background-color: transparent;
}
}
2 changes: 1 addition & 1 deletion src/knockout/components/list/list-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- ko if: $data.item.needSeparator -->
<div data-bind="css: $data.model.cssClasses.itemSeparator"></div>
<!-- /ko -->
<div data-bind="style: { paddingInlineStart: $data.model.getItemIndent($data.item) }, css: $data.model.cssClasses.itemBody, attr: { title: $data.item.locTitle.calculatedText }, event: { mouseover: function(m, e) { $data.hover(e, $data); return true; } }">
<div data-bind="style: { paddingInlineStart: $data.model.getItemIndent($data.item) }, css: $data.model.cssClasses.itemBody, attr: { title: $data.item.locTitle.calculatedText }, event: { mouseover: function(m, e) { $data.hover(e, $data); return true; }, mouseleave: function(m, e) { $data.leave(e, $data); return true; } }">
<!-- ko component: { name: $data.item.component || 'sv-list-item-content', params: { item: $data.item, model: $data.model } } -->
<!-- /ko -->
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/knockout/components/list/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ko.components.register("sv-list-item", {
if (event.type === "mouseover") {
data.model.onItemHover(data.item);
}
},
leave: (event: MouseEvent, data: any) => {
data.model.onItemLeave(data.item);
}
};
},
Expand Down
5 changes: 5 additions & 0 deletions src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export let defaultListCss = {
itemWithIcon: "sv-list__item--with-icon",
itemDisabled: "sv-list__item--disabled",
itemFocused: "sv-list__item--focused",
itemHovered: "sv-list__item--hovered",
itemTextWrap: "sv-list__item-text--wrap",
itemIcon: "sv-list__item-icon",
itemMarkerIcon: "sv-list-item__marker-icon",
Expand Down Expand Up @@ -199,6 +200,9 @@ export class ListModel<T extends BaseAction = Action> extends ActionContainer<T>
public onItemHover = (itemValue: T): void => {
this.mouseOverHandler(itemValue);
}
public onItemLeave(itemValue: T) {
itemValue.hidePopupDelayed(this.subItemsHideDelay);
}

public isItemDisabled: (itemValue: T) => boolean = (itemValue: T) => {
return itemValue.enabled !== undefined && !itemValue.enabled;
Expand Down Expand Up @@ -229,6 +233,7 @@ export class ListModel<T extends BaseAction = Action> extends ActionContainer<T>
.append(this.cssClasses.itemDisabled, this.isItemDisabled(itemValue))
.append(this.cssClasses.itemFocused, this.isItemFocused(itemValue))
.append(this.cssClasses.itemSelected, this.isItemSelected(itemValue))
.append(this.cssClasses.itemHovered, itemValue.isHovered)
.append(this.cssClasses.itemTextWrap, this.textWrapEnabled)
.append(itemValue.css)
.toString();
Expand Down
3 changes: 2 additions & 1 deletion src/vue/components/list/list-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

<div :style="{ paddingInlineStart: model.getItemIndent(item) }" v-bind:class="model.cssClasses.itemBody"
:title="item.locTitle.calculatedText"
@mouseover="(e) => model.onItemHover(item)">
@mouseover="(e) => model.onItemHover(item)"
@mouseleave="(e) => model.onItemLeave(item)">
<sv-svg-icon v-if="item.iconName && !item.component" v-bind:class="model.cssClasses.itemIcon"
:iconName="item.iconName" :size="item.iconSize"></sv-svg-icon>
<survey-string v-if="!item.component" :locString="item.locTitle" />
Expand Down

0 comments on commit 15cc176

Please sign in to comment.