diff --git a/test/spec/ui/button-spec.js b/test/spec/ui/button-spec.js index 650be4ed95..6b24923978 100644 --- a/test/spec/ui/button-spec.js +++ b/test/spec/ui/button-spec.js @@ -28,6 +28,7 @@ describe("test/ui/button-spec", function () { expect(aButton.label).toEqual(""); }); it("should have a default value", function () { + expect(aButton.label).toEqual("Button"); aButton.label = ""; expect(aButton.label).toEqual(""); aButton.label = void 0; @@ -42,6 +43,12 @@ describe("test/ui/button-spec", function () { aButton.draw(); expect(aButton.element.value).toEqual( "hello"); }); + + it("should has not default value when the Button is subclassed", function () { + var MyButton = Button.specialize(); + aButton = new MyButton(); + expect(aButton.label).toEqual(""); + }); }); describe("draw", function () { var aButton; diff --git a/ui/button.reel/button.js b/ui/button.reel/button.js index 7b5f2ebec0..379103cad4 100644 --- a/ui/button.reel/button.js +++ b/ui/button.reel/button.js @@ -104,7 +104,8 @@ var Button = exports.Button = Control.specialize(/** @lends module:"montage/ui/n */ label: { get: function () { - return this._label; + return this._label !== void 0 && this._label !== null ? + this._label : this.defaultLabel; }, set: function (value) { if (typeof value !== "undefined" && this.converter) { @@ -220,6 +221,17 @@ var Button = exports.Button = Control.specialize(/** @lends module:"montage/ui/n } }, + constructor: { + value: function () { + this.super(); + + if (this.constructor !== Button) { + // no default value when the Button Component is subclassed + this.defaultLabel = ""; + } + } + }, + // HTMLInputElement/HTMLButtonElement methods // click() deliberately omitted (it isn't available on