From 3896c89100643c9db9c72a58f6c519ca271cd047 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Fri, 31 May 2024 15:00:13 +0300 Subject: [PATCH 1/8] support action call in onItemClick for list model #8129 --- src/list.ts | 6 +++++- tests/listModelTests.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/list.ts b/src/list.ts index 8742a7a2a0..aa0d98c782 100644 --- a/src/list.ts +++ b/src/list.ts @@ -32,7 +32,7 @@ export let defaultListCss = { }; export interface IListModel { items: Array; - onSelectionChanged: (item: IAction, ...params: any[]) => void; + onSelectionChanged?: (item: IAction, ...params: any[]) => void; allowSelection?: boolean; searchEnabled?: boolean; selectedItem?: IAction; @@ -186,6 +186,10 @@ export class ListModel extends ActionContainer if (this.allowSelection) { this.selectedItem = itemValue; } + const action = (itemValue as IAction).action; + if (!!action) { + action(itemValue); + } if (!!this.onSelectionChanged) { this.onSelectionChanged(itemValue); } diff --git a/tests/listModelTests.ts b/tests/listModelTests.ts index 6870bb3c2b..ea316ba61e 100644 --- a/tests/listModelTests.ts +++ b/tests/listModelTests.ts @@ -440,3 +440,30 @@ QUnit.test("ListModel search in subitems", function (assert) { ListModel.MINELEMENTCOUNT = oldValueMINELEMENTCOUNT; }); +QUnit.test("ListModel onItemClick", function (assert) { + + let items: Array = []; + for (let index = 0; index < 4; ++index) { + items.push(new Action({ id: "test" + index, title: "test" + index })); + } + let actionCalled = 0; + let selectCalled = 0; + items[1].action = () => { + actionCalled++; + }; + const list = new ListModel({ + items: items, + onSelectionChanged: () => { + selectCalled++; + }, + allowSelection: true + } as any); + + list.onItemClick(items[0]); + assert.equal(actionCalled, 0); + assert.equal(selectCalled, 1); + + list.onItemClick(items[1]); + assert.equal(actionCalled, 1); + assert.equal(selectCalled, 2); +}); \ No newline at end of file From 9eaa13eabe697975f55debbe4465f64ac930c1e9 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Fri, 31 May 2024 15:09:38 +0300 Subject: [PATCH 2/8] make onSelectionChanged optional --- src/actions/action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/action.ts b/src/actions/action.ts index 435b95ec6f..a3b56b5604 100644 --- a/src/actions/action.ts +++ b/src/actions/action.ts @@ -428,7 +428,7 @@ export class Action extends BaseAction implements IAction, ILocalizableOwner { private createLocTitle(): LocalizableString { return this.createLocalizableString("title", this, true); } - public setItems(items: Array, onSelectionChanged: (item: Action, ...params: any[]) => void): void { + public setItems(items: Array, onSelectionChanged?: (item: Action, ...params: any[]) => void): void { this.markerIconName = "icon-next_16x16"; this.component = "sv-list-item-group"; this.items = [...items]; From 23952618c7a15e1afa4a6526755784d7b1234927 Mon Sep 17 00:00:00 2001 From: Aleksey Novikov Date: Fri, 31 May 2024 15:32:45 +0300 Subject: [PATCH 3/8] check if onSelectionChanged exists --- src/actions/action.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/actions/action.ts b/src/actions/action.ts index a3b56b5604..f249857f0a 100644 --- a/src/actions/action.ts +++ b/src/actions/action.ts @@ -170,7 +170,9 @@ export function createDropdownActionModelAdvanced(actionOptions: IAction, listOp const originalSelectionChanged = listOptions.onSelectionChanged; listOptions.onSelectionChanged = (item: Action, ...params: any[]) => { if (newAction.hasTitle) { newAction.title = item.title; } - originalSelectionChanged(item, params); + if (originalSelectionChanged) { + originalSelectionChanged(item, params); + } }; const popupModel: PopupModel = createPopupModelWithListModel(listOptions, popupOptions); @@ -192,7 +194,9 @@ export function createDropdownActionModelAdvanced(actionOptions: IAction, listOp export function createPopupModelWithListModel(listOptions: IListModel, popupOptions: IPopupOptionsBase): PopupModel { const listModel: ListModel = new ListModel(listOptions as any); listModel.onSelectionChanged = (item: Action) => { - listOptions.onSelectionChanged(item); + if (listOptions.onSelectionChanged) { + listOptions.onSelectionChanged(item); + } popupModel.hide(); }; From 93a895ced96757cf7d44d5cfef4cc26960d73c2d Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Fri, 31 May 2024 16:26:46 +0300 Subject: [PATCH 4/8] fix marker color for selected item --- src/common-styles/sv-list.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common-styles/sv-list.scss b/src/common-styles/sv-list.scss index 899f294348..5c15e575e7 100644 --- a/src/common-styles/sv-list.scss +++ b/src/common-styles/sv-list.scss @@ -162,6 +162,10 @@ li:focus .sv-list__item.sv-list__item--selected { .sv-list__item-icon use { fill: $background; } + + .sv-list-item__marker-icon use { + fill: $primary-foreground; + } } .sv-multi-select-list .sv-list__item.sv-list__item--selected, From c48be5da371474265c28fa3b244040c1bc78654e Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Fri, 31 May 2024 16:36:41 +0300 Subject: [PATCH 5/8] fix list item height & inner popup position --- src/common-styles/sv-list.scss | 2 +- src/common-styles/sv-popup.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common-styles/sv-list.scss b/src/common-styles/sv-list.scss index 5c15e575e7..cb94ed9add 100644 --- a/src/common-styles/sv-list.scss +++ b/src/common-styles/sv-list.scss @@ -90,7 +90,7 @@ .sv-list__item--with-icon.sv-list__item--with-icon { padding: 0; - .sv-list__item-body { + & > .sv-list__item-body { padding-top: calcSize(1.5); padding-bottom: calcSize(1.5); gap: calcSize(2); diff --git a/src/common-styles/sv-popup.scss b/src/common-styles/sv-popup.scss index f3f440855c..8199b24563 100644 --- a/src/common-styles/sv-popup.scss +++ b/src/common-styles/sv-popup.scss @@ -27,7 +27,7 @@ sv-popup { } .sv-popup-inner .sv-popup__container { - margin-top: calcSize(-1); + margin-top: calcSize(-0.5); } .sv-popup__container { From f7f34f3852ba47be6e8b624709c2ac757e8e66e4 Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Fri, 31 May 2024 17:56:30 +0300 Subject: [PATCH 6/8] show icon while searching --- src/list.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/list.ts b/src/list.ts index aa0d98c782..c45a67c07b 100644 --- a/src/list.ts +++ b/src/list.ts @@ -90,10 +90,16 @@ export class ListModel extends ActionContainer let actions = super.getRenderedActions(); if (this.filterString) { - let newActions = [] as Array; + let newActions: Array = []; actions.forEach(action => { newActions.push(action); - if (action.items) action.items.forEach(item => newActions.push(item as T)); + if (action.items) { + action.items.forEach(item => { + const a = new Action(item); + a.iconName = action.iconName; + newActions.push(a as IAction as T); + }); + } }); return newActions; } From 687c09b2aba475f7952ed037d7bdaddaf76a285e Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Mon, 3 Jun 2024 10:38:40 +0300 Subject: [PATCH 7/8] fix inner popup position --- src/common-styles/sv-popup.scss | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common-styles/sv-popup.scss b/src/common-styles/sv-popup.scss index 8199b24563..13c985acf6 100644 --- a/src/common-styles/sv-popup.scss +++ b/src/common-styles/sv-popup.scss @@ -26,7 +26,11 @@ sv-popup { height: 0; } -.sv-popup-inner .sv-popup__container { +.sv-popup-inner > .sv-popup__container { + margin-top: calcSize(-1); +} + +.sv-list__item--with-icon .sv-popup-inner > .sv-popup__container { margin-top: calcSize(-0.5); } From eff6cd0290c0f90662fae9062e403efdc69ad5d7 Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Mon, 3 Jun 2024 10:40:58 +0300 Subject: [PATCH 8/8] fix for show icon while searching --- src/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/list.ts b/src/list.ts index c45a67c07b..8ffc14a447 100644 --- a/src/list.ts +++ b/src/list.ts @@ -96,7 +96,7 @@ export class ListModel extends ActionContainer if (action.items) { action.items.forEach(item => { const a = new Action(item); - a.iconName = action.iconName; + if (!a.iconName) { a.iconName = action.iconName; } newActions.push(a as IAction as T); }); }