Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #448 from lucasreppewelander/t/447
Browse files Browse the repository at this point in the history
Feature: Added the optional `DropdownView#class` property to set a custom CSS class on the main element in DOM. Closes #447.

Thanks to [@lucasreppewelander](https://github.com/lucasreppewelander)!
  • Loading branch information
oleq authored Oct 10, 2018
2 parents 3b44c73 + ad9e8a8 commit 9cdcd4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/dropdown/dropdownview.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ export default class DropdownView extends View {
*/
this.set( 'isEnabled', true );

/**
* (Optional) The additional CSS class set on the dropdown {@link #element}.
*
* @observable
* @member {String} #class
*/
this.set( 'class' );

/**
* Tracks information about DOM focus in the dropdown.
*
Expand Down Expand Up @@ -147,6 +155,7 @@ export default class DropdownView extends View {
class: [
'ck',
'ck-dropdown',
bind.to( 'class' ),
bind.if( 'isEnabled', 'ck-disabled', value => !value )
]
},
Expand Down
11 changes: 8 additions & 3 deletions tests/dropdown/dropdownview.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ describe( 'DropdownView', () => {
} );
} );

describe( 'DOM', () => {
describe( 'view#element .ck-disabled class to view#isEnabled', () => {
it( 'is activated', () => {
describe( 'DOM element bindings', () => {
describe( 'class', () => {
it( 'reacts on view#isEnabled', () => {
view.isEnabled = true;
expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.false;

view.isEnabled = false;
expect( view.element.classList.contains( 'ck-disabled' ) ).to.be.true;
} );

it( 'reacts on view#class', () => {
view.class = 'custom-css-class';
expect( view.element.classList.contains( 'custom-css-class' ) ).to.be.true;
} );
} );
} );
} );
Expand Down

0 comments on commit 9cdcd4a

Please sign in to comment.