Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-multi-combobox): revert selection after close button is pressed #3938

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions packages/main/src/MultiComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,37 @@ class MultiComboBox extends UI5Element {
}

_listSelectionChange(event) {
event.target.items.forEach(item => {
this.items.forEach(mcbItem => {
if (mcbItem._id === item.getAttribute("data-ui5-token-id")) {
mcbItem.selected = item.selected;
}
});
});
// sync list items and cb items
this.syncItems(event.target.items);

this.fireSelectionChange();
// don't call selection change right after selection as user can cancel it on phone
if (!isPhone()) {
this.fireSelectionChange();
}

if (!event.detail.selectionComponentPressed && !isSpace(event.detail)) {
this.allItemsPopover.close();
this.value = "";

// if the item (not checkbox) is clicked, call the selection change
if (isPhone()) {
this.fireSelectionChange();
}

this.fireEvent("input");
}
}

syncItems(listItems) {
listItems.forEach(item => {
this.items.forEach(mcbItem => {
if (mcbItem._id === item.getAttribute("data-ui5-token-id")) {
mcbItem.selected = item.selected;
}
});
});
}

fireSelectionChange() {
this.fireEvent("selection-change", { items: this._getSelectedItems() });
// Angular 2 way data binding
Expand Down Expand Up @@ -697,6 +711,15 @@ class MultiComboBox extends UI5Element {
}
}

_beforeOpen() {
this._itemsBeforeOpen = this.items.map(item => {
return {
ref: item,
selected: item.selected,
};
});
}

async onAfterRendering() {
await this._getRespPopover();
await this._getList();
Expand Down Expand Up @@ -727,6 +750,22 @@ class MultiComboBox extends UI5Element {
}
}

handleCancel() {
this._itemsBeforeOpen.forEach(item => {
item.ref.selected = item.selected;
});

this.togglePopover();
}

handleOK() {
if (isPhone()) {
this.fireSelectionChange();
}

this.togglePopover();
}

async openPopover() {
const popover = await this._getPopover();

Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/MultiComboBoxPopover.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class="ui5-multi-combobox-all-items-responsive-popover"
hide-arrow
_disable-initial-focus
@ui5-selection-change={{_listSelectionChange}}
@ui5-after-close={{_toggle}}
@ui5-before-open={{_beforeOpen}}
@ui5-after-open={{_toggle}}
>
{{#if _isPhone}}
Expand All @@ -16,7 +16,7 @@
class="ui5-responsive-popover-close-btn"
icon="decline"
design="Transparent"
@click="{{togglePopover}}"
@click="{{handleCancel}}"
>
</ui5-button>
</div>
Expand Down Expand Up @@ -65,7 +65,7 @@
{{/if}}
{{/unless}}

<ui5-list separators="None" mode="MultiSelect" class="ui5-multi-combobox-all-items-list">
<ui5-list @ui5-selection-change={{_listSelectionChange}} separators="None" mode="MultiSelect" class="ui5-multi-combobox-all-items-list">
{{#each _filteredItems}}
<ui5-li
type="{{../_listItemsType}}"
Expand All @@ -83,7 +83,7 @@
<div slot="footer" class="ui5-responsive-popover-footer">
<ui5-button
design="Transparent"
@click="{{togglePopover}}"
@click="{{handleOK}}"
>{{_dialogOkButton}}</ui5-button>
</div>
{{/if}}
Expand Down