Search using non-sanitised input value

This commit is contained in:
Matt Triff 2021-12-30 22:05:03 -05:00
parent 1b4d3553ef
commit 9605f367f9
3 changed files with 37 additions and 1 deletions

View File

@ -1734,6 +1734,38 @@ describe('choices', () => {
});
});
describe('events', () => {
describe('search', () => {
beforeEach(() => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;
instance = new Choices('[data-choice]', {
allowHTML: false,
searchEnabled: true,
});
});
it('details are passed', (done) => {
const query =
'This is a <search> query & a "test" with characters that should not be sanitised.';
instance.input.value = query;
instance.input.focus();
instance.passedElement.element.addEventListener('search', (event) => {
expect(event.detail).to.eql({
value: query,
resultCount: 0,
});
done();
});
instance._onKeyUp({ target: null, keyCode: null });
});
});
});
describe('private methods', () => {
describe('_createGroupsFragment', () => {
let _createChoicesFragmentStub;

View File

@ -1513,7 +1513,7 @@ class Choices implements Choices {
this._isSearching = false;
this._store.dispatch(activateChoices(true));
} else if (canSearch) {
this._handleSearch(this.input.value);
this._handleSearch(this.input.rawValue);
}
}

View File

@ -52,6 +52,10 @@ export default class Input {
this.element.value = value;
}
get rawValue(): string {
return this.element.value;
}
addEventListeners(): void {
this.element.addEventListener('paste', this._onPaste);
this.element.addEventListener('input', this._onInput, {