-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sbb-autocomplete-grid): component implementation (#2512)
- Loading branch information
1 parent
fa5557c
commit 0fc5f40
Showing
97 changed files
with
7,017 additions
and
900 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './autocomplete-grid/autocomplete-grid.js'; | ||
export * from './autocomplete-grid/autocomplete-grid-button.js'; | ||
export * from './autocomplete-grid/autocomplete-grid-cell.js'; | ||
export * from './autocomplete-grid/autocomplete-grid-optgroup.js'; | ||
export * from './autocomplete-grid/autocomplete-grid-option.js'; | ||
export * from './autocomplete-grid/autocomplete-grid-row.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 @@ | ||
export * from './autocomplete-grid-button/autocomplete-grid-button.js'; |
116 changes: 116 additions & 0 deletions
116
...rid/autocomplete-grid-button/__snapshots__/autocomplete-grid-button.snapshot.spec.snap.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,116 @@ | ||
/* @web/test-runner snapshot v1 */ | ||
export const snapshots = {}; | ||
|
||
snapshots["sbb-autocomplete-grid-button renders DOM"] = | ||
`<sbb-autocomplete-grid-button | ||
aria-disabled="false" | ||
data-action="" | ||
data-button="" | ||
dir="ltr" | ||
icon-name="pie-small" | ||
id="sbb-autocomplete-grid-button-1" | ||
role="button" | ||
> | ||
</sbb-autocomplete-grid-button> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button renders Shadow DOM"] = | ||
`<span class="sbb-action-base sbb-autocomplete-grid-button"> | ||
<slot name="icon"> | ||
<sbb-icon | ||
aria-hidden="true" | ||
data-namespace="default" | ||
name="pie-small" | ||
role="img" | ||
> | ||
</sbb-icon> | ||
</slot> | ||
</span> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders Shadow DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button renders disabled DOM"] = | ||
`<sbb-autocomplete-grid-button | ||
aria-disabled="true" | ||
data-action="" | ||
data-button="" | ||
dir="ltr" | ||
disabled="" | ||
icon-name="pie-small" | ||
id="sbb-autocomplete-grid-button-3" | ||
role="button" | ||
> | ||
</sbb-autocomplete-grid-button> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders disabled DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button renders disabled Shadow DOM"] = | ||
`<span class="sbb-action-base sbb-autocomplete-grid-button"> | ||
<slot name="icon"> | ||
<sbb-icon | ||
aria-hidden="true" | ||
data-namespace="default" | ||
name="pie-small" | ||
role="img" | ||
> | ||
</sbb-icon> | ||
</slot> | ||
</span> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders disabled Shadow DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button renders negative without icon DOM"] = | ||
`<sbb-autocomplete-grid-button | ||
aria-disabled="false" | ||
data-action="" | ||
data-button="" | ||
dir="ltr" | ||
id="sbb-autocomplete-grid-button-5" | ||
negative="" | ||
role="button" | ||
> | ||
</sbb-autocomplete-grid-button> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders negative without icon DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button renders negative without icon Shadow DOM"] = | ||
`<span class="sbb-action-base sbb-autocomplete-grid-button"> | ||
<slot name="icon"> | ||
</slot> | ||
</span> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button renders negative without icon Shadow DOM */ | ||
|
||
snapshots["sbb-autocomplete-grid-button A11y tree Chrome"] = | ||
`<p> | ||
{ | ||
"role": "WebArea", | ||
"name": "", | ||
"children": [ | ||
{ | ||
"role": "button", | ||
"name": "" | ||
} | ||
] | ||
} | ||
</p> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button A11y tree Chrome */ | ||
|
||
snapshots["sbb-autocomplete-grid-button A11y tree Firefox"] = | ||
`<p> | ||
{ | ||
"role": "document", | ||
"name": "", | ||
"children": [ | ||
{ | ||
"role": "button", | ||
"name": "" | ||
} | ||
] | ||
} | ||
</p> | ||
`; | ||
/* end snapshot sbb-autocomplete-grid-button A11y tree Firefox */ | ||
|
15 changes: 15 additions & 0 deletions
15
src/elements/autocomplete-grid/autocomplete-grid-button/autocomplete-grid-button.scss
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,15 @@ | ||
@use '../../core/styles' as sbb; | ||
|
||
// Box-sizing rules contained in typography are not traversing Shadow DOM boundaries. We need to include box-sizing mixin in every component. | ||
@include sbb.box-sizing; | ||
|
||
:host { | ||
// Use !important here to not interfere with Firefox focus ring definition | ||
// which appears in normalize css of several frameworks. | ||
outline: none !important; | ||
display: block; | ||
|
||
--sbb-button-display: flex; | ||
} | ||
|
||
@include sbb.icon-button('.sbb-autocomplete-grid-button', '::slotted(sbb-icon), sbb-icon'); |
104 changes: 104 additions & 0 deletions
104
...ents/autocomplete-grid/autocomplete-grid-button/autocomplete-grid-button.snapshot.spec.ts
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,104 @@ | ||
import { expect } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
|
||
import { fixture, testA11yTreeSnapshot } from '../../core/testing/private.js'; | ||
import { waitForLitRender } from '../../core/testing.js'; | ||
|
||
import type { SbbAutocompleteGridButtonElement } from './autocomplete-grid-button.js'; | ||
import '../../form-field.js'; | ||
import '../autocomplete-grid.js'; | ||
import '../autocomplete-grid-row.js'; | ||
import '../autocomplete-grid-cell.js'; | ||
import './autocomplete-grid-button.js'; | ||
|
||
describe('sbb-autocomplete-grid-button', () => { | ||
describe('renders', () => { | ||
let root: SbbAutocompleteGridButtonElement; | ||
beforeEach(async () => { | ||
root = ( | ||
await fixture(html` | ||
<sbb-autocomplete-grid origin="anchor"> | ||
<sbb-autocomplete-grid-row> | ||
<sbb-autocomplete-grid-cell> | ||
<sbb-autocomplete-grid-button icon-name="pie-small"></sbb-autocomplete-grid-button> | ||
</sbb-autocomplete-grid-cell> | ||
</sbb-autocomplete-grid-row> | ||
</sbb-autocomplete-grid> | ||
<div id="anchor"></div> | ||
`) | ||
).querySelector('sbb-autocomplete-grid-button')!; | ||
await waitForLitRender(root); | ||
}); | ||
|
||
it('DOM', async () => { | ||
await expect(root).dom.to.be.equalSnapshot(); | ||
}); | ||
|
||
it('Shadow DOM', async () => { | ||
await expect(root).shadowDom.to.be.equalSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('renders disabled', () => { | ||
let root: SbbAutocompleteGridButtonElement; | ||
beforeEach(async () => { | ||
root = ( | ||
await fixture(html` | ||
<sbb-autocomplete-grid origin="anchor"> | ||
<sbb-autocomplete-grid-row> | ||
<sbb-autocomplete-grid-cell> | ||
<sbb-autocomplete-grid-button | ||
disabled | ||
icon-name="pie-small" | ||
></sbb-autocomplete-grid-button> | ||
</sbb-autocomplete-grid-cell> | ||
</sbb-autocomplete-grid-row> | ||
</sbb-autocomplete-grid> | ||
<div id="anchor"></div> | ||
`) | ||
).querySelector('sbb-autocomplete-grid-button')!; | ||
await waitForLitRender(root); | ||
}); | ||
|
||
it('DOM', async () => { | ||
await expect(root).dom.to.be.equalSnapshot(); | ||
}); | ||
|
||
it('Shadow DOM', async () => { | ||
await expect(root).shadowDom.to.be.equalSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('renders negative without icon', () => { | ||
let root: SbbAutocompleteGridButtonElement; | ||
beforeEach(async () => { | ||
root = ( | ||
await fixture(html` | ||
<sbb-form-field negative> | ||
<input /> | ||
<sbb-autocomplete-grid> | ||
<sbb-autocomplete-grid-row> | ||
<sbb-autocomplete-grid-cell> | ||
<sbb-autocomplete-grid-button></sbb-autocomplete-grid-button> | ||
</sbb-autocomplete-grid-cell> | ||
</sbb-autocomplete-grid-row> | ||
</sbb-autocomplete-grid> | ||
</sbb-form-field> | ||
`) | ||
).querySelector('sbb-autocomplete-grid-button')!; | ||
await waitForLitRender(root); | ||
}); | ||
|
||
it('DOM', async () => { | ||
await expect(root).dom.to.be.equalSnapshot(); | ||
}); | ||
|
||
it('Shadow DOM', async () => { | ||
await expect(root).shadowDom.to.be.equalSnapshot(); | ||
}); | ||
}); | ||
|
||
testA11yTreeSnapshot( | ||
html`<sbb-autocomplete-grid-button icon-name="pie-small"></sbb-autocomplete-grid-button>`, | ||
); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/elements/autocomplete-grid/autocomplete-grid-button/autocomplete-grid-button.spec.ts
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,53 @@ | ||
import { assert, expect } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
|
||
import { fixture } from '../../core/testing/private.js'; | ||
import { EventSpy, waitForCondition, waitForLitRender } from '../../core/testing.js'; | ||
|
||
import { SbbAutocompleteGridButtonElement } from './autocomplete-grid-button.js'; | ||
|
||
describe(`sbb-autocomplete-grid-button`, () => { | ||
let element: SbbAutocompleteGridButtonElement; | ||
|
||
beforeEach(async () => { | ||
element = await fixture( | ||
html`<sbb-autocomplete-grid-button>Button</sbb-autocomplete-grid-button>`, | ||
); | ||
}); | ||
|
||
it('renders', async () => { | ||
assert.instanceOf(element, SbbAutocompleteGridButtonElement); | ||
}); | ||
|
||
describe('events', () => { | ||
it('dispatches event on click', async () => { | ||
const clickSpy = new EventSpy('click'); | ||
|
||
element.click(); | ||
await waitForCondition(() => clickSpy.events.length === 1); | ||
expect(clickSpy.count).to.be.equal(1); | ||
}); | ||
|
||
it('should not dispatch event on click if disabled', async () => { | ||
element.setAttribute('disabled', 'true'); | ||
|
||
await waitForLitRender(element); | ||
|
||
const clickSpy = new EventSpy('click'); | ||
|
||
element.click(); | ||
expect(clickSpy.count).not.to.be.greaterThan(0); | ||
}); | ||
|
||
it('should stop propagating host click if disabled', async () => { | ||
element.disabled = true; | ||
|
||
const clickSpy = new EventSpy('click'); | ||
|
||
element.dispatchEvent(new CustomEvent('click')); | ||
await waitForLitRender(element); | ||
|
||
expect(clickSpy.count).not.to.be.greaterThan(0); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/elements/autocomplete-grid/autocomplete-grid-button/autocomplete-grid-button.ssr.spec.ts
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,21 @@ | ||
import { assert } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
|
||
import { fixture } from '../../core/testing/private.js'; | ||
|
||
import { SbbAutocompleteGridButtonElement } from './autocomplete-grid-button.js'; | ||
|
||
describe(`sbb-autocomplete-grid-button ssr`, () => { | ||
let element: SbbAutocompleteGridButtonElement; | ||
|
||
beforeEach(async () => { | ||
element = await fixture( | ||
html`<sbb-autocomplete-grid-button>Button</sbb-autocomplete-grid-button>`, | ||
{ modules: ['./autocomplete-grid-button.ts'] }, | ||
); | ||
}); | ||
|
||
it('renders', async () => { | ||
assert.instanceOf(element, SbbAutocompleteGridButtonElement); | ||
}); | ||
}); |
Oops, something went wrong.