Skip to content

@attr boolean/number setter function called with an empty string (v2-beta) #295

Description

@ryecroft

This is maybe related to #117, but not 100% sure on that.

With a component defined like this:

import { controller, attr } from '@github/catalyst'

@controller
class TestComponentElement extends HTMLElement {

  @attr get booleanProp() {
    return false
  }
  set booleanProp( _v: boolean ) {
    console.dir( `booleanProp type: ${ typeof _v }` )
    console.dir( `booleanProp value: '${ _v }'` )
  }

  connectedCallback() {
    this.booleanProp = true
  }

}

and html like this (note the lack of an initial boolean-prop value):

<test-component></test-component>

I get these log messages:

booleanProp type: boolean
booleanProp value: 'true'
booleanProp type: string
booleanProp value: ''

Changing the html to include an initial value like this:

<test-component boolean-prop='anything'></test-component>

get's rid of that final empty string call:

booleanProp type: boolean
booleanProp value: 'true'

Maybe this is a limitation? Hopefully this isn't another ghost bug, sorry about the last one 🫣

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions