mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
Resolve conflict + add test
This commit is contained in:
commit
8214eea7a9
|
@ -1,4 +1,4 @@
|
||||||
import { calcWidthOfInput } from '../lib/utils';
|
import { calcWidthOfInput, stripHTML } from '../lib/utils';
|
||||||
|
|
||||||
export default class Input {
|
export default class Input {
|
||||||
constructor({ element, type, classNames, placeholderValue }) {
|
constructor({ element, type, classNames, placeholderValue }) {
|
||||||
|
@ -25,7 +25,7 @@ export default class Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
get value() {
|
get value() {
|
||||||
return this.element.value;
|
return stripHTML(this.element.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListeners() {
|
addEventListeners() {
|
||||||
|
@ -119,23 +119,11 @@ export default class Input {
|
||||||
this.element.removeAttribute('aria-activedescendant');
|
this.element.removeAttribute('aria-activedescendant');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Input event
|
|
||||||
* @return
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_onInput() {
|
_onInput() {
|
||||||
if (this.type !== 'select-one') {
|
if (this.type !== 'select-one') {
|
||||||
this.setWidth();
|
this.setWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Paste event
|
|
||||||
* @param {Object} e Event
|
|
||||||
* @return
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_onPaste(e) {
|
_onPaste(e) {
|
||||||
// Disable pasting into the input if option has been set
|
// Disable pasting into the input if option has been set
|
||||||
if (e.target === this.element && this.preventPaste) {
|
if (e.target === this.element && this.preventPaste) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ describe('components/input', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onInput', () => {
|
describe('_onInput', () => {
|
||||||
let setWidthStub;
|
let setWidthStub;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -103,7 +103,7 @@ describe('components/input', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onPaste', () => {
|
describe('_onPaste', () => {
|
||||||
let eventMock;
|
let eventMock;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -130,7 +130,7 @@ describe('components/input', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onFocus', () => {
|
describe('_onFocus', () => {
|
||||||
it('sets isFocussed flag to true', () => {
|
it('sets isFocussed flag to true', () => {
|
||||||
expect(instance.isFocussed).to.equal(false);
|
expect(instance.isFocussed).to.equal(false);
|
||||||
instance._onFocus();
|
instance._onFocus();
|
||||||
|
@ -138,7 +138,7 @@ describe('components/input', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onBlur', () => {
|
describe('_onBlur', () => {
|
||||||
it('sets isFocussed flag to false', () => {
|
it('sets isFocussed flag to false', () => {
|
||||||
instance.isFocussed = true;
|
instance.isFocussed = true;
|
||||||
instance._onBlur();
|
instance._onBlur();
|
||||||
|
@ -342,8 +342,15 @@ describe('components/input', () => {
|
||||||
it('sets value of element to passed value', () => {
|
it('sets value of element to passed value', () => {
|
||||||
const value = 'test';
|
const value = 'test';
|
||||||
instance.element.value = value;
|
instance.element.value = value;
|
||||||
const actualResponse = instance.value;
|
expect(instance.value).to.equal(value);
|
||||||
expect(actualResponse).to.equal(value);
|
});
|
||||||
|
|
||||||
|
it('strips HTML from value', () => {
|
||||||
|
const value = '<script>somethingMalicious();</script>';
|
||||||
|
instance.element.value = value;
|
||||||
|
expect(instance.value).to.equal(
|
||||||
|
'<script&rt;somethingMalicious();</script&rt;',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue