-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add itemClassNameGenerator to generate CSS class names (#7305)
- Loading branch information
1 parent
b636efb
commit df22622
Showing
12 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/combo-box/test/item-class-name-generator-lit.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../theme/lumo/vaadin-lit-combo-box.js'; | ||
import './item-class-name-generator.common.js'; |
3 changes: 3 additions & 0 deletions
3
packages/combo-box/test/item-class-name-generator-polymer.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './not-animated-styles.js'; | ||
import '../vaadin-combo-box.js'; | ||
import './item-class-name-generator.common.js'; |
57 changes: 57 additions & 0 deletions
57
packages/combo-box/test/item-class-name-generator.common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; | ||
import { getAllItems } from './helpers.js'; | ||
|
||
describe('itemClassNameGenerator', () => { | ||
let comboBox; | ||
|
||
beforeEach(async () => { | ||
comboBox = fixtureSync('<vaadin-combo-box></vaadin-combo-box>'); | ||
await nextRender(); | ||
comboBox.items = ['foo', 'bar', 'baz']; | ||
}); | ||
|
||
it('should set class name on dropdown items', async () => { | ||
comboBox.itemClassNameGenerator = (item) => `item-${item}`; | ||
comboBox.open(); | ||
await nextRender(); | ||
const items = getAllItems(comboBox); | ||
expect(items[0].className).to.equal('item-foo'); | ||
expect(items[1].className).to.equal('item-bar'); | ||
expect(items[2].className).to.equal('item-baz'); | ||
}); | ||
|
||
it('should remove class name when return value is empty string', async () => { | ||
comboBox.itemClassNameGenerator = (item) => `item-${item}`; | ||
comboBox.open(); | ||
await nextRender(); | ||
|
||
comboBox.close(); | ||
comboBox.itemClassNameGenerator = () => ''; | ||
|
||
comboBox.open(); | ||
await nextRender(); | ||
|
||
const items = getAllItems(comboBox); | ||
expect(items[0].className).to.equal(''); | ||
expect(items[1].className).to.equal(''); | ||
expect(items[2].className).to.equal(''); | ||
}); | ||
|
||
it('should remove class name when generator is set to null', async () => { | ||
comboBox.itemClassNameGenerator = (item) => `item-${item}`; | ||
comboBox.open(); | ||
await nextRender(); | ||
|
||
comboBox.close(); | ||
comboBox.itemClassNameGenerator = null; | ||
|
||
comboBox.open(); | ||
await nextRender(); | ||
|
||
const items = getAllItems(comboBox); | ||
expect(items[0].className).to.equal(''); | ||
expect(items[1].className).to.equal(''); | ||
expect(items[2].className).to.equal(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters