Reputation: 2726
I'm relatively new to Dojo and trying to get the hang of dijits. After consulting the docs for Dojo's dijit/form/Button widget here:
http://dojotoolkit.org/reference-guide/1.9/dijit/form/Button.html
I attempted to create a button showing only an icon (showLabel: false). That attempt can be seen in this fiddle:
http://jsfiddle.net/msweeney/23Mxh/
or assembled from the code:
<body>
<button type="button" id="testButton"></button>
</body>
.plusIcon {
background-image: url("http://png-2.findicons.com/files/icons/2152/snowish/128/gtk_add.png");
background-position: center;
background-repeat: no-repeat;
height: 19px;
width: 19px;
}
require(["dojo/parser", "dijit/form/Button", "dojo/domReady!"],
function (parser, Button) {
parser.parse();
var testButton = new Button({
label: "test button",
showLabel: false,
iconClass: "plusIcon",
onClick: function () {
alert("test button clicked")
}
}, "testButton");
testButton.startup();
});
I can't seem to figure out what I'm doing wrong here. In particular:
Note: I'd be glad to show pictures to illustrate what I'm getting and what I'd like to be getting, but I don't have enough reputation yet.
Upvotes: 0
Views: 2423
Reputation: 7852
When using dijit widgets, you need to include a theme css file (such as claro.css) and set the class attribute on the body tag
I updated your jsfiddle with the extra css resource and the class="claro" attribute on the body tag.
html:
<body class="claro">
<button type="button" id="testButton"></button>
</body>
js:
require(["dojo/parser", "dijit/form/Button", "dojo/domReady!"],
function (parser, Button) {
var testButton = new Button({
label: "test button",
showLabel: false,
iconClass: "plusIcon",
onClick: function () {
alert("test button clicked")
}
}, "testButton");
testButton.startup();
});
css:
.plusIcon {
background-image: url("http://png-2.findicons.com/files/icons/2152/snowish/128/gtk_add.png");
background-position: center;
background-repeat: no-repeat;
height: 19px;
width: 19px;
}
Upvotes: 2