more concistent disable function

This commit is contained in:
Keegan
2016-02-14 17:14:19 -08:00
parent 1180bf2abc
commit 64fa83528e
4 changed files with 27 additions and 10 deletions
+2
View File
@@ -4,6 +4,7 @@
* @returns {ClayEvents} * @returns {ClayEvents}
*/ */
function disable() { function disable() {
this.$element.set('+disabled');
this.$manipulatorTarget.set('disabled', true); this.$manipulatorTarget.set('disabled', true);
return this.trigger('disabled'); return this.trigger('disabled');
} }
@@ -12,6 +13,7 @@ function disable() {
* @returns {ClayEvents} * @returns {ClayEvents}
*/ */
function enable() { function enable() {
this.$element.set('-disabled');
this.$manipulatorTarget.set('disabled', false); this.$manipulatorTarget.set('disabled', false);
return this.trigger('enabled'); return this.trigger('enabled');
} }
+5
View File
@@ -86,6 +86,11 @@ label {
.component { .component {
padding-bottom: $item-spacing-v; padding-bottom: $item-spacing-v;
@include tap-highlight(); @include tap-highlight();
&.disabled {
opacity: 0.25;
pointer-events: none;
}
} }
.section { .section {
+1 -7
View File
@@ -9,15 +9,9 @@
box-shadow: $box-shadow-small-components; box-shadow: $box-shadow-small-components;
} }
input:disabled ~ .value,
input:disabled ~ .label {
opacity: 0.25;
}
.picker-wrap { .picker-wrap {
left: 0; left: 0;
top: 0; top: 0;
top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
position: fixed; position: fixed;
@@ -47,7 +41,7 @@
height: 0; height: 0;
width: 100%; width: 100%;
padding: 0 0 100% 0; // overridden with inline style padding: 0 0 100% 0; // overridden with inline style
margin: 0.6em 0 0em; margin: 0.6em 0 0;
.color-box-container { .color-box-container {
position: absolute; position: absolute;
+19 -3
View File
@@ -40,8 +40,15 @@ describe('manipulators', function() {
var handlerSpy = sinon.spy(); var handlerSpy = sinon.spy();
var clayItem = fixture.clayItem(itemType); var clayItem = fixture.clayItem(itemType);
clayItem.on('disabled', handlerSpy); clayItem.on('disabled', handlerSpy);
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
false
);
clayItem.disable(); clayItem.disable();
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
true
);
assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), true); assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), true);
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once'); assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem'); assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');
@@ -54,13 +61,22 @@ describe('manipulators', function() {
* @return {void} * @return {void}
*/ */
function testEnable(itemType) { function testEnable(itemType) {
describe('.disable()', function() { describe('.enable()', function() {
it('disables the field then triggers an "enabled" event', function() { it('enables the field then triggers an "enabled" event', function() {
var handlerSpy = sinon.spy(); var handlerSpy = sinon.spy();
var clayItem = fixture.clayItem(itemType); var clayItem = fixture.clayItem(itemType);
clayItem.on('enabled', handlerSpy); clayItem.on('enabled', handlerSpy);
clayItem.disable();
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
true
);
clayItem.enable(); clayItem.enable();
assert.strictEqual(
clayItem.$element[0].classList.contains('disabled'),
false
);
assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), false); assert.strictEqual(clayItem.$manipulatorTarget.get('disabled'), false);
assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once'); assert.strictEqual(handlerSpy.callCount, 1, 'handler not called once');
assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem'); assert(handlerSpy.calledOn(clayItem), 'handler not called on clayItem');