Skip to content

Commit

Permalink
fix(ld-label): throws on click when without child
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Mar 16, 2023
1 parent 4ef2998 commit 519521b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/liquid/components/ld-label/ld-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export class LdLabel implements ClonesAttributes {
const inputElement: HTMLElement = this.el.querySelector(
'ld-input, ld-textarea, ld-toggle, ld-select, ld-button, ld-checkbox, ld-radio, input, textarea, button, select'
)
const clickedInsideInputElement =
event.target === inputElement ||
inputElement.contains(event.target as Node)

if (
const notClickedInsideNotDisabled =
inputElement &&
!clickedInsideInputElement &&
!(
event.target === inputElement ||
inputElement.contains(event.target as Node)
) &&
!inputElement['disabled']
) {

if (notClickedInsideNotDisabled) {
if ('focusInner' in inputElement) {
await (inputElement as unknown as InnerFocusable).focusInner()
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/liquid/components/ld-label/test/ld-label.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ describe('ld-label', () => {
expect(ldInput.focus).not.toHaveBeenCalled()
expect(ldInput.focusInner).toHaveBeenCalledTimes(1)
})

it('does not throw, when label without child elements is clicked', async () => {
const page = await newSpecPage({
components: [LdLabel],
html: '<ld-label>Label text</ld-label>',
})
await page.root.shadowRoot.querySelector('slot').click()
// No need to assert anything here.
})
})

1 comment on commit 519521b

@vercel
Copy link

@vercel vercel bot commented on 519521b Mar 16, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

liquid – ./

liquid-git-main-uxsd.vercel.app
liquid-uxsd.vercel.app
liquid-oxygen.vercel.app

Please sign in to comment.