Skip to content

Commit 60c677a

Browse files
vorobeyAndrei Vorobev
andauthored
TagBox: Fix removing grouped options behavior (T1329352) (#33742)
Co-authored-by: Andrei Vorobev <andrei.vorobev@devexpress.com>
1 parent 856990a commit 60c677a

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

packages/devextreme/js/__internal/ui/m_tag_box.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,10 +1396,12 @@ class TagBox<
13961396
}
13971397

13981398
_removeTagElement($tag) {
1399+
const { showMultiTagOnly, maxDisplayedTags } = this.option();
13991400
if ($tag.hasClass(TAGBOX_MULTI_TAG_CLASS)) {
1400-
if (!this.option('showMultiTagOnly')) {
1401-
const { maxDisplayedTags } = this.option();
1402-
this.option('value', this._getValue().slice(0, maxDisplayedTags));
1401+
if (!showMultiTagOnly && isDefined(maxDisplayedTags)) {
1402+
const displayedTagsCount = Math.max(0, maxDisplayedTags - 1);
1403+
const newValue = this._getValue().slice(0, displayedTagsCount);
1404+
this.option('value', newValue);
14031405
} else {
14041406
this.clear();
14051407
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/tagBox.tests.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ QUnit.module('multi tag support', {
10601060
assert.deepEqual($tag.text(), '3 selected', 'text is correct');
10611061
});
10621062

1063-
QUnit.test('multi tag should deselect overflow tags only when showMultiTagOnly is false', function(assert) {
1063+
QUnit.test('multi tag remove should deselect all items grouped under it when showMultiTagOnly is false (T1329352)', function(assert) {
10641064
const $tagBox = $('#tagBox').dxTagBox({
10651065
items: [1, 2, 3, 4],
10661066
value: [1, 2, 4],
@@ -1069,15 +1069,30 @@ QUnit.module('multi tag support', {
10691069
});
10701070

10711071
const tagBox = $tagBox.dxTagBox('instance');
1072-
const $multiTag = $tagBox.find('.' + TAGBOX_MULTI_TAG_CLASS);
1072+
const $multiTag = $tagBox.find(`.${TAGBOX_MULTI_TAG_CLASS}`);
10731073

10741074
$($multiTag.find(`.${TAGBOX_TAG_REMOVE_BUTTON_CLASS}`)).trigger('dxclick');
10751075

1076-
assert.equal($tagBox.find('.' + TAGBOX_TAG_CLASS).length, 2, 'only 2 tags remain');
1077-
assert.deepEqual(tagBox.option('value'), [1, 2], 'value is correct');
1078-
assert.deepEqual(this.getTexts($tagBox.find('.' + TAGBOX_TAG_CLASS)), ['1', '2'], 'tags have correct text');
1076+
assert.equal($tagBox.find(`.${TAGBOX_TAG_CLASS}`).length, 1, 'only the individually rendered tag remains');
1077+
assert.deepEqual(tagBox.option('value'), [1], 'only the value visible as an individual tag remains');
10791078
});
10801079

1080+
QUnit.test('multi tag remove should deselect all items when showMultiTagOnly is true (T1329352)', function(assert) {
1081+
const $tagBox = $('#tagBox').dxTagBox({
1082+
items: [1, 2, 3, 4],
1083+
value: [1, 2, 4],
1084+
maxDisplayedTags: 2,
1085+
showMultiTagOnly: true
1086+
});
1087+
1088+
const tagBox = $tagBox.dxTagBox('instance');
1089+
const $multiTag = $tagBox.find(`.${TAGBOX_MULTI_TAG_CLASS}`);
1090+
1091+
$($multiTag.find(`.${TAGBOX_TAG_REMOVE_BUTTON_CLASS}`)).trigger('dxclick');
1092+
1093+
assert.equal($tagBox.find(`.${TAGBOX_TAG_CLASS}`).length, 0, 'no tags remain');
1094+
assert.deepEqual(tagBox.option('value'), [], 'value is cleared');
1095+
});
10811096

10821097
QUnit.test('TagBox should preserve reverse click order in leading tag when showMultiTagOnly is false', function(assert) {
10831098
const $tagBox = $('#tagBox').dxTagBox({

0 commit comments

Comments
 (0)