+ *
* ★ ${data.label}
*
* `);
diff --git a/src/scripts/interfaces/templates.ts b/src/scripts/interfaces/templates.ts
index 279ac3a0f..b2d9b0221 100644
--- a/src/scripts/interfaces/templates.ts
+++ b/src/scripts/interfaces/templates.ts
@@ -15,6 +15,7 @@ export type TemplateOptions = Pick<
| 'removeItemLabelText'
| 'searchEnabled'
| 'labelId'
+ | 'itemDeselectText'
>;
export const NoticeTypes = {
diff --git a/src/scripts/templates.ts b/src/scripts/templates.ts
index 84749fb0b..72f51a5c1 100644
--- a/src/scripts/templates.ts
+++ b/src/scripts/templates.ts
@@ -251,6 +251,7 @@ const templates: TemplatesInterface = {
{
allowHTML,
classNames: { item, itemChoice, itemSelectable, selectedState, itemDisabled, description, placeholder },
+ itemDeselectText,
}: TemplateOptions,
choice: ChoiceFull,
selectText: string,
@@ -307,6 +308,9 @@ const templates: TemplatesInterface = {
if (selectText) {
div.dataset.selectText = selectText;
}
+ if (itemDeselectText) {
+ div.dataset.deselectText = itemDeselectText;
+ }
if (choice.group) {
div.dataset.groupId = `${choice.group.id}`;
}
diff --git a/src/styles/choices.scss b/src/styles/choices.scss
index 9d2c62a4a..e36fe2cc4 100644
--- a/src/styles/choices.scss
+++ b/src/styles/choices.scss
@@ -294,13 +294,28 @@ $choices-z-index: 1 !default;
text-align: right;
}
}
+ [data-type*="select-multiple"] & .#{$choices-selector}__item--selectable {
+ &[data-deselect-text] {
+ @media (min-width: 640px) {
+ &.is-selected::after {
+ content: attr(data-deselect-text);
+ }
+ }
+ }
+ }
.#{$choices-selector}__item--selectable {
&[data-select-text] {
@media (min-width: 640px) {
padding-right: 100px;
- &::after {
+ &.is-selected {
+ background-color: $choices-primary-color;
+ color: #fff;
+ }
+ &:not(.is-selected)::after {
content: attr(data-select-text);
+ }
+ &::after {
font-size: $choices-font-size-sm;
opacity: 0;
position: absolute;
diff --git a/test-e2e/tests/select-multiple.spec.ts b/test-e2e/tests/select-multiple.spec.ts
index 9e3afe35c..e1622e9a1 100644
--- a/test-e2e/tests/select-multiple.spec.ts
+++ b/test-e2e/tests/select-multiple.spec.ts
@@ -255,6 +255,24 @@ describe(`Choices - select multiple`, () => {
describe('selecting choices', () => {
const selectedChoiceText = 'Choice 1';
+ test('shows deselect text on hover of selected choice', async ({ page, bundle }) => {
+ const suite = new SelectTestSuit(page, bundle, testUrl, testId);
+ await suite.startWithClick();
+
+ await suite.choices.first().hover();
+
+ const deselectText = 'Deselect';
+ const afterContent = await page.evaluate(({testId, deselectText}) => {
+ const choice = document.querySelector(`[data-test-hook=${testId}] .choices__item--choice.is-selected`) as HTMLElement;
+ choice.dataset.deselectText = deselectText;
+ return getComputedStyle(choice, ':after').content;
+ },
+ {testId, deselectText},
+ );
+
+ await expect(afterContent).toContain(`\"${deselectText}\"`);
+ });
+
test('not removing selected choice from dropdown list', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
@@ -284,6 +302,7 @@ describe(`Choices - select multiple`, () => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
+ await suite.choices.first().click();
const count = await suite.choices.count();
for (let i = 1; i < count + 1; i++) {
@@ -330,6 +349,32 @@ describe(`Choices - select multiple`, () => {
});
});
+ describe('dont-render-selected-items', () => {
+ const testId = 'dont-render-selected-items';
+ describe('selecting choices', () => {
+ test('all available choices', async ({ page, bundle }) => {
+ const suite = new SelectTestSuit(page, bundle, testUrl, testId);
+ await suite.startWithClick();
+
+ await suite.choices.first().click();
+ const count = await suite.choices.count();
+
+ for (let i = 1; i < count + 1; i++) {
+ await suite.expectVisibleDropdown();
+ await suite.getChoiceWithText(`Choice ${i}`).click();
+ await suite.advanceClock();
+ await suite.expectedItemCount(0);
+ if (i < count) {
+ await expect(suite.getChoiceWithText(`Choice ${i}`)).toHaveClass(/is-selected/);
+ await expect(suite.selectableChoices).toHaveCount(count);
+ } else {
+ await suite.expectHiddenNotice();
+ }
+ }
+ });
+ });
+ });
+
describe('remove button', () => {
const testId = 'remove-button';
describe('on click', () => {
diff --git a/test-e2e/tests/select-one.spec.ts b/test-e2e/tests/select-one.spec.ts
index b66c44e4c..98d1540de 100644
--- a/test-e2e/tests/select-one.spec.ts
+++ b/test-e2e/tests/select-one.spec.ts
@@ -73,6 +73,24 @@ describe(`Choices - select one`, () => {
await expect(suite.items.last()).not.toHaveText('!--');
});
+ test('does not show deselect text on hover of selected choice', async ({ page, bundle }) => {
+ const suite = new SelectTestSuit(page, bundle, testUrl, testId);
+ await suite.startWithClick();
+
+ await suite.choices.first().hover();
+
+ const deselectText = 'Deselect';
+ const afterContent = await page.evaluate(({testId, deselectText}) => {
+ const choice = document.querySelector(`[data-test-hook=${testId}] .choices__item--choice.is-selected`) as HTMLElement;
+ choice.dataset.deselectText = deselectText;
+ return getComputedStyle(choice, ':after').content;
+ },
+ {testId, deselectText},
+ );
+
+ await expect(afterContent).not.toContain(`\"${deselectText}\"`);
+ });
+
test('does not remove selected choice from dropdown list', async ({ page, bundle }) => {
const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.startWithClick();
diff --git a/test/scripts/templates.test.ts b/test/scripts/templates.test.ts
index 6528152a1..9c54cb04d 100644
--- a/test/scripts/templates.test.ts
+++ b/test/scripts/templates.test.ts
@@ -400,6 +400,7 @@ describe('templates', () => {
});
const itemSelectText = 'test 6';
+ const itemDeselectText = 'test 7';
let data;
@@ -422,10 +423,11 @@ describe('templates', () => {
class="${getClassNames(choiceOptions.classNames.item).join(' ')} ${getClassNames(
choiceOptions.classNames.itemChoice,
).join(' ')} ${getClassNames(choiceOptions.classNames.itemSelectable).join(' ')}"
- data-select-text="${itemSelectText}"
data-choice
data-id="${data.id}"
data-value="${data.value}"
+ data-select-text="${itemSelectText}"
+ data-deselect-text="${itemDeselectText}"
data-choice-selectable
id="${data.elementId}"
role="option"
@@ -453,10 +455,11 @@ describe('templates', () => {
class="${getClassNames(choiceOptions.classNames.item).join(' ')} ${getClassNames(
choiceOptions.classNames.itemChoice,
).join(' ')} ${getClassNames(choiceOptions.classNames.itemDisabled).join(' ')}"
- data-select-text="${itemSelectText}"
data-choice
data-id="${data.id}"
data-value="${data.value}"
+ data-select-text="${itemSelectText}"
+ data-deselect-text="${itemDeselectText}"
data-choice-disabled
aria-disabled="true"
id="${data.elementId}"
@@ -487,10 +490,11 @@ describe('templates', () => {
).join(
' ',
)} ${choiceOptions.classNames.selectedState} ${getClassNames(choiceOptions.classNames.itemSelectable).join(' ')}"
- data-select-text="${itemSelectText}"
data-choice
data-id="${data.id}"
data-value="${data.value}"
+ data-select-text="${itemSelectText}"
+ data-deselect-text="${itemDeselectText}"
data-choice-selectable
id="${data.elementId}"
role="option"
@@ -520,10 +524,11 @@ describe('templates', () => {
).join(
' ',
)} ${choiceOptions.classNames.placeholder} ${getClassNames(choiceOptions.classNames.itemSelectable).join(' ')}"
- data-select-text="${itemSelectText}"
data-choice
data-id="${data.id}"
data-value="${data.value}"
+ data-select-text="${itemSelectText}"
+ data-deselect-text="${itemDeselectText}"
data-choice-selectable
id="${data.elementId}"
role="option"
@@ -551,10 +556,11 @@ describe('templates', () => {
class="${getClassNames(choiceOptions.classNames.item).join(' ')} ${getClassNames(
choiceOptions.classNames.itemChoice,
).join(' ')} ${getClassNames(choiceOptions.classNames.itemSelectable).join(' ')}"
- data-select-text="${itemSelectText}"
data-choice
data-id="${data.id}"
data-value="${data.value}"
+ data-select-text="${itemSelectText}"
+ data-deselect-text="${itemDeselectText}"
data-group-id="${data.groupId}"
data-choice-selectable
id="${data.elementId}"