From bca64c78e4d6ab1d94930660282711f7cc5ec42d Mon Sep 17 00:00:00 2001 From: Alexandre Couret Date: Fri, 22 Sep 2017 14:31:48 +0100 Subject: [PATCH] Remove checkbox label when auto === 'none' (#375) * [ADD] Remove checkbox label when auto === 'none' * [ADD] Checkbox auto 'none' test --- lib/components.js | 3 +-- test/index.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/components.js b/lib/components.js index 5aa93d73..93d918ca 100644 --- a/lib/components.js +++ b/lib/components.js @@ -297,8 +297,7 @@ class Checkbox extends Component { getLocals() { const locals = super.getLocals(); - // checkboxes must always have a label - locals.label = locals.label || this.getDefaultLabel(); + locals.label = this.props.ctx.auto !== 'none' ? locals.label || this.getDefaultLabel() : null; [ 'help', diff --git a/test/index.js b/test/index.js index a54d5567..7d9cebd9 100644 --- a/test/index.js +++ b/test/index.js @@ -688,7 +688,7 @@ test('Select:nullOption', function (tape) { var Checkbox = core.Checkbox; test('Checkbox:label', function (tape) { - tape.plan(2); + tape.plan(3); tape.strictEqual( new Checkbox({ @@ -708,6 +708,14 @@ test('Checkbox:label', function (tape) { 'mylabel', 'should handle `label` option'); + tape.strictEqual( + new Checkbox({ + type: t.Boolean, + options: {}, + ctx: ctxNone + }).getLocals().label, + null, + 'should have null `label` when auto `none`'); }); test('Checkbox:help', function (tape) { @@ -1152,4 +1160,3 @@ test('List:should support unions', (assert) => { assert.strictEqual(component.getItems()[0].input.props.type, UnknownAccount); }); -