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

refactor(shoelace): tests failed to check hidden menu #237

Merged
merged 1 commit into from
Sep 5, 2022
Merged
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
5 changes: 5 additions & 0 deletions .changeset/quick-pugs-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/shaperone-wc-shoelace": patch
---

Missing imports in `sh-sl-autocomplete`
10 changes: 8 additions & 2 deletions packages/wc-shoelace/elements/sh-sl-autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { customElement, property, query } from 'lit/decorators.js'
import type { GraphPointer } from 'clownface'
import { SlInput } from '@shoelace-style/shoelace'
import { stop } from '../lib/handlers.js'
import '@shoelace-style/shoelace/dist/components/input/input.js'
import '@shoelace-style/shoelace/dist/components/icon/icon.js'
import '@shoelace-style/shoelace/dist/components/dropdown/dropdown.js'
import '@shoelace-style/shoelace/dist/components/menu/menu.js'
import '@shoelace-style/shoelace/dist/components/menu-item/menu-item.js'

@customElement('sh-sl-autocomplete')
export class ShSlAutocomplete extends LitElement {
static get styles() {
return css`
:host([empty]) sl-menu {
[hidden] {
display: none;
}
`
Expand All @@ -20,7 +25,7 @@ export class ShSlAutocomplete extends LitElement {
@property({ type: String })
inputValue = ''

@property({ type: Boolean, reflect: true })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is reflect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Reflect is to keep a sync between HTML element attribute and property value.

https://lit.dev/docs/components/properties/#reflected-attributes

@property({ type: Boolean })
empty = true

@property({ type: Boolean })
Expand All @@ -37,6 +42,7 @@ export class ShSlAutocomplete extends LitElement {
<sl-icon name="search" slot="suffix"></sl-icon>
</sl-input>
<sl-menu hoist .value=${this.selected?.value}
?hidden="${this.empty}"
placeholder="Missing data!"
@sl-select=${this.dispatchItemSelected}>
<slot @slotchange=${this.updateEmpty}></slot>
Expand Down
4 changes: 2 additions & 2 deletions packages/wc-shoelace/test/elements/sh-sl-autocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe('packages/wc-shoelace/elements/sh-sl-autocomplete', () => {
expect(el.empty).to.be.true
})

it('has empty attribute when empty', async () => {
it('hides menu when empty', async () => {
// when
const el = await fixture<ShSlAutocomplete>(html`<sh-sl-autocomplete></sh-sl-autocomplete>`)

// then
expect(el).attr('empty').to.eq('')
expect(el.renderRoot.querySelector('sl-menu')).attr('hidden').to.eq('')
})
})