Support disabled attribute for menu item

This commit is contained in:
Wei Wei 2017-04-23 17:40:14 +08:00
Родитель 7e255e969b
Коммит bf26e27f90
4 изменённых файлов: 13 добавлений и 5 удалений

Просмотреть файл

@ -42,6 +42,11 @@ window.toolbar = new ToolbarView({
text: 'The 2nd DropdownItem', text: 'The 2nd DropdownItem',
id: 'dropdown-item-2nd', id: 'dropdown-item-2nd',
onClick: () => console.log('click dropdown-item-2nd'), onClick: () => console.log('click dropdown-item-2nd'),
}, {
text: 'The 3rd DropdownItem',
id: 'dropdown-item-3rd',
disabled: true,
onClick: () => console.log('click dropdown-item-3rd'),
}, { }, {
type: 'dropdown-divider', type: 'dropdown-divider',
}, { }, {
@ -77,4 +82,3 @@ window.toolbar = new ToolbarView({
}, },
}], }],
}).render(); }).render();

Просмотреть файл

@ -5,4 +5,3 @@ li.dropdown-item(role='presentation', class=classes, id=id)
span.text=text span.text=text
if iconRight if iconRight
span.icon-right(class=iconRight) span.icon-right(class=iconRight)

Просмотреть файл

@ -6,20 +6,25 @@ export function renderDropdownItem(dropdownItem) {
classes: [], classes: [],
id: _.uniqueId('dropdown-item-'), id: _.uniqueId('dropdown-item-'),
text: '', text: '',
disabled: false,
iconLeft: null, iconLeft: null,
iconRight: null, iconRight: null,
tabindex: -1, tabindex: -1,
onClick: null, onClick: null,
}, dropdownItem); }, dropdownItem);
if (options.disabled) {
options.classes = _.union(options.classes, ['disabled']);
}
const html = dropdownItemTemplate(options); const html = dropdownItemTemplate(options);
const events = {}; const events = {};
const { id, onClick } = options; const { id, onClick } = options;
if (_.isFunction(onClick)) { if (_.isFunction(onClick) && !options.disabled) {
events[`click .dropdown-item#${id}`] = onClick; events[`click .dropdown-item#${id}`] = onClick;
} }
return { html, events }; return { html, events };
} }

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"main": "dist/backbone-toolbar.js", "main": "dist/backbone-toolbar.js",
"version": "0.0.5", "version": "0.1.1",
"files": [ "files": [
"dist" "dist"
], ],