Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure ql-active gets set on toolbar checklist buttons #1944

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import Module from '../core/module';

let debug = logger('quill:toolbar');

let formatLookup = {
unchecked: 'check',
checked: 'check',
};

class Toolbar extends Module {
constructor(quill, options) {
Expand Down Expand Up @@ -133,11 +137,13 @@ class Toolbar extends Module {
if (range == null) {
input.classList.remove('ql-active');
} else if (input.hasAttribute('value')) {
// lookup correct format for checklists, which don't match the toolbar value
let normalizedFormat = formatLookup[formats[format]] || formats[format];
// both being null should match (default values)
// '1' should match with 1 (headers)
let isActive = formats[format] === input.getAttribute('value') ||
(formats[format] != null && formats[format].toString() === input.getAttribute('value')) ||
(formats[format] == null && !input.getAttribute('value'));
let isActive = normalizedFormat === input.getAttribute('value') ||
(normalizedFormat != null && normalizedFormat.toString() === input.getAttribute('value')) ||
(normalizedFormat == null && !input.getAttribute('value'));
input.classList.toggle('ql-active', isActive);
} else {
input.classList.toggle('ql-active', formats[format] != null);
Expand Down
12 changes: 11 additions & 1 deletion test/unit/modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ describe('Toolbar', function() {
<p><a href="http://quilljs.com/">0123</a></p>
<p class="ql-align-center">5678</p>
<p><span class="ql-size-small">01</span><span class="ql-size-large">23</span></p>
<ul data-checked="false"><li>27</li></ul>
`);
this.quill = new Quill(container, {
modules: {
toolbar: [
['bold', 'link'],
[{ 'size': ['small', false, 'large'] }],
[{ 'align': '' }, { 'align': 'center' }]
[{ 'align': '' }, { 'align': 'center' }],
[{ 'list': 'check' }]
]
},
theme: 'snow'
Expand Down Expand Up @@ -159,5 +161,13 @@ describe('Toolbar', function() {
expect(centerButton.classList.contains('ql-active')).toBe(false);
expect(leftButton.classList.contains('ql-active')).toBe(false);
});

it('check list', function() {
let checkListButton = this.container.parentNode.querySelector('button.ql-list[value="check"]');
this.quill.setSelection(27);
expect(checkListButton.classList.contains('ql-active')).toBe(true);
this.quill.setSelection(2);
expect(checkListButton.classList.contains('ql-active')).toBe(false);
});
});
});