diff --git a/.github/workflows/browsers.yml b/.github/workflows/browsers.yml index 88b84da1..87b5824e 100644 --- a/.github/workflows/browsers.yml +++ b/.github/workflows/browsers.yml @@ -63,7 +63,7 @@ jobs: - uses: actions/upload-artifact@v4 if: failure() with: - name: screenshot-${{ matrix.os }} + name: screenshot-${{ matrix.os }}-${{ matrix.browser }} path: test-results/**/*.png - uses: actions/upload-artifact@v4 if: '!cancelled()' diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f16c5c2..6717a541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## [11.0.2] +## [11.0.3] + +### Bug Fixes (from 11.0.0) +* Fix input text - method setValue didn't work [#1207](https://github.com/Choices-js/Choices/issues/1207) + +## [11.0.2] (2024-09-05) ### Features (from 11.0.0) * Pass `getClassNames` as the 3rd argument to `callbackOnCreateTemplates` callback diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index 1f211273..70babc07 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -19,7 +19,6 @@ import { removeClassesFromElement, resolveNoticeFunction, resolveStringFunction, - sanitise, sortByRank, strToEl, } from './lib/utils'; @@ -737,7 +736,7 @@ class Choices { } as InputGroup; } - this._addGroup(mapInputToChoice(group, true)); + this._addGroup(mapInputToChoice(group, true)); } else { let choice = groupOrChoice; if (!isDefaultLabel || !isDefaultValue) { @@ -747,7 +746,7 @@ class Choices { label: choice[label], } as InputChoice; } - this._addChoice(mapInputToChoice(choice, false)); + this._addChoice(mapInputToChoice(choice, false)); } }); @@ -1324,7 +1323,7 @@ class Choices { if (this.passedElement.value) { const elementItems: ChoiceFull[] = this.passedElement.value .split(config.delimiter) - .map((e: InputChoice | string) => mapInputToChoice(e, false)); + .map((e: string) => mapInputToChoice(e, false, this.config.allowHtmlUserInput)); this._presetChoices = this._presetChoices.concat(elementItems); } this._presetChoices.forEach((choice: ChoiceFull) => { @@ -1740,21 +1739,7 @@ class Choices { return; } - const sanitisedValue = sanitise(value); - const userValue = - this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value }; - this._addChoice( - mapInputToChoice( - { - value: userValue, - label: userValue, - selected: true, - } as InputChoice, - false, - ), - true, - true, - ); + this._addChoice(mapInputToChoice(value, false, this.config.allowHtmlUserInput), true, true); addedItem = true; } diff --git a/src/scripts/lib/choice-input.ts b/src/scripts/lib/choice-input.ts index 22a60dd8..ca990f94 100644 --- a/src/scripts/lib/choice-input.ts +++ b/src/scripts/lib/choice-input.ts @@ -2,7 +2,7 @@ import { InputChoice } from '../interfaces/input-choice'; import { InputGroup } from '../interfaces/input-group'; import { GroupFull } from '../interfaces/group-full'; import { ChoiceFull } from '../interfaces/choice-full'; -import { unwrapStringForRaw } from './utils'; +import { sanitise, unwrapStringForRaw } from './utils'; type MappedInputTypeToChoiceType = T extends InputGroup ? GroupFull @@ -27,13 +27,18 @@ export const stringToHtmlClass = (input: string | string[] | undefined): string[ export const mapInputToChoice = ( value: T, allowGroup: boolean, + allowRawString: boolean = true, ): MappedInputTypeToChoiceType => { if (typeof value === 'string') { - const result: ChoiceFull = mapInputToChoice( + const sanitisedValue = sanitise(value); + const userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value }; + + const result: ChoiceFull = mapInputToChoice( { value, - label: value, - } as InputChoice, + label: userValue, + selected: true, + }, false, ); @@ -47,7 +52,7 @@ export const mapInputToChoice = ( throw new TypeError(`optGroup is not allowed`); } const group = groupOrChoice; - const choices = group.choices.map((e) => mapInputToChoice(e, false)); + const choices = group.choices.map((e) => mapInputToChoice(e, false)); const result: GroupFull = { id: 0, // actual ID will be assigned during _addGroup diff --git a/test-e2e/__screenshots__/chromium-darwin.png b/test-e2e/__screenshots__/chromium-darwin.png index 30b6d750..0a989893 100644 Binary files a/test-e2e/__screenshots__/chromium-darwin.png and b/test-e2e/__screenshots__/chromium-darwin.png differ diff --git a/test-e2e/__screenshots__/chromium-linux.png b/test-e2e/__screenshots__/chromium-linux.png index bd8a3a20..95d0f860 100644 Binary files a/test-e2e/__screenshots__/chromium-linux.png and b/test-e2e/__screenshots__/chromium-linux.png differ diff --git a/test-e2e/__screenshots__/chromium-win32.png b/test-e2e/__screenshots__/chromium-win32.png index 8579f823..af44f531 100644 Binary files a/test-e2e/__screenshots__/chromium-win32.png and b/test-e2e/__screenshots__/chromium-win32.png differ diff --git a/test-e2e/__screenshots__/firefox-darwin.png b/test-e2e/__screenshots__/firefox-darwin.png deleted file mode 100644 index 8393c410..00000000 Binary files a/test-e2e/__screenshots__/firefox-darwin.png and /dev/null differ diff --git a/test-e2e/__screenshots__/firefox-linux.png b/test-e2e/__screenshots__/firefox-linux.png index 4a52746b..5462ba7b 100644 Binary files a/test-e2e/__screenshots__/firefox-linux.png and b/test-e2e/__screenshots__/firefox-linux.png differ diff --git a/test-e2e/__screenshots__/firefox-win32.png b/test-e2e/__screenshots__/firefox-win32.png deleted file mode 100644 index d5150137..00000000 Binary files a/test-e2e/__screenshots__/firefox-win32.png and /dev/null differ diff --git a/test-e2e/__screenshots__/webkit-darwin.png b/test-e2e/__screenshots__/webkit-darwin.png index 1b463fdf..e2aaf71b 100644 Binary files a/test-e2e/__screenshots__/webkit-darwin.png and b/test-e2e/__screenshots__/webkit-darwin.png differ diff --git a/test-e2e/__screenshots__/webkit-linux.png b/test-e2e/__screenshots__/webkit-linux.png index ebd1b5a3..e43c1655 100644 Binary files a/test-e2e/__screenshots__/webkit-linux.png and b/test-e2e/__screenshots__/webkit-linux.png differ diff --git a/test-e2e/__screenshots__/webkit-win32.png b/test-e2e/__screenshots__/webkit-win32.png deleted file mode 100644 index 30b88ef7..00000000 Binary files a/test-e2e/__screenshots__/webkit-win32.png and /dev/null differ