baloise / design-system

The Baloise Design System consists of reusable components and a clearly defined visual style, that can be assembled together to build any number of applications.
https://design.baloise.dev
Apache License 2.0
97 stars 26 forks source link

🐛 fix(form-controls): connect aria-labelledby with the correct label of the bar-field #825

Closed GinaBiondo-aperto closed 11 months ago

GinaBiondo-aperto commented 1 year ago

Current Behavior

Aria-labelledby is not set correctly for and

Expected Behavior

The connection between group-tags and bal-field-label should be established correctly to set aria-labelledby for the group-tags

Steps to Reproduce

Set a radio group or checkbox group within a field tag with label

Version

12.10.0

Browsers

All

Device

All

Code Reproduction URL

No response

Additional Information

No response

Code of Conduct

hirsch88 commented 1 year ago

  /**
   * @internal
   */
  @Prop() context?: 'field-label' | 'radio-label' | 'radio-button-label' | 'checkbox-label' | 'checkbox-button-label'
hirsch88 commented 1 year ago

export interface BalLabeledBy {
  labeledBy: string
}

class Component implements BalLabeledBy {

  /**
   * @internal
   */
  @Prop() labeledBy: string

  sync() {
    if(this.context === 'field-label'){
      const controls = this.el.closest('bal-field-label')?.closest('bal-field')?.querySelector('bal-field-control')
      this.htmlFor = controls[0]
      controls.forEach(control => control.ariaLabeldBy = this.id)
    }
  }
}
mladenplaninicic commented 1 year ago

/cib

github-actions[bot] commented 1 year ago

Branch fix/issue-825 created!