Skip to content

Commit 4d69b69

Browse files
committed
Merge pull request #2 from devex-web-frontend/feature/disabled_modifier
seems fine
2 parents c13e85e + ec315d5 commit 4d69b69

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/js/colorpicker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var Colorpicker = (function(DX, window, document, undefined) {
1515
var event = DX.Event,
1616
CN_COLORPICKER = 'colorPicker',
1717
M_OPEN = 'opened',
18+
M_DISABLED = 'disabled',
1819
CN_COLORPICKER_LABEL = CN_COLORPICKER + '--label',
1920
CN_COLORPICKER_VALUE = CN_COLORPICKER + '--value',
2021
defaultColors = {
@@ -79,7 +80,9 @@ var Colorpicker = (function(DX, window, document, undefined) {
7980
});
8081
initListeners();
8182
setColorListHandler();
82-
83+
if (disabled) {
84+
setDisabled();
85+
}
8386
DX.Event.trigger(input, Colorpicker.E_CREATED, {
8487
detail: {
8588
block: block,
@@ -103,7 +106,6 @@ var Colorpicker = (function(DX, window, document, undefined) {
103106

104107
function initAppearance() {
105108
var parent = DX.Dom.getParent(input);
106-
107109
block = DX.Dom.createElement('div', {
108110
className: CN_COLORPICKER,
109111
innerHTML: DX.Tmpl.process(config.INNER_TMPL, config)
@@ -277,10 +279,12 @@ var Colorpicker = (function(DX, window, document, undefined) {
277279
function setDisabled() {
278280
hideDropDown();
279281
disabled = true;
282+
DX.Bem.addModifier(block, M_DISABLED);
280283
}
281284

282285
function setEnabled() {
283286
disabled = false;
287+
DX.Bem.removeModifier(block, M_DISABLED);
284288
}
285289

286290
/**

test/js/colorpicker.unit.spec.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*/
44
describe('Colorpicker', function() {
55
var elementTmpl = [
6-
'<input type="text" value="" id="test" />'
7-
].join(''),
8-
defaultColorList = ['#511717', '#000000', '#fefefe'],
9-
colorPicker,
10-
testElement;
6+
'<input type="text" value="" id="test" />'
7+
].join(''),
8+
defaultColorList = ['#511717', '#000000', '#fefefe'],
9+
colorPicker,
10+
testElement;
1111

1212
beforeEach(function() {
1313
document.body.innerHTML = elementTmpl;
@@ -22,12 +22,41 @@ describe('Colorpicker', function() {
2222
window.Colorpicker.colorList = [];
2323
});
2424

25+
describe('disabled', function() {
26+
27+
var getDisabled;
28+
29+
beforeEach(function(){
30+
testElement.disabled = true;
31+
getDisabled = function() {
32+
return document.querySelectorAll('.colorPicker-disabled');
33+
}
34+
});
35+
36+
it('should has modifier `disabled` if input has attribute `disabled`', function() {
37+
new Colorpicker(testElement);
38+
expect(getDisabled().length).toEqual(1)
39+
});
40+
41+
it('sholud remove modifier `disabled` on method `setEnabled`', function() {
42+
var colorPicker = new Colorpicker(testElement);
43+
colorPicker.setEnabled();
44+
expect(getDisabled().length).toEqual(0)
45+
});
46+
47+
it('sholud add modifier `disabled` on method `setDisabled`', function() {
48+
test.disabled = false;
49+
var colorPicker = new Colorpicker(testElement);
50+
colorPicker.setDisabled();
51+
expect(getDisabled().length).toEqual(1)
52+
})
53+
54+
});
2555

2656
describe('dropDownData', function() {
2757

2858
var dropDown,
2959
dataList,
30-
temp,
3160
initColorPicker;
3261

3362
beforeEach(function(){

0 commit comments

Comments
 (0)