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

Adds Label as a new web component #27344

Merged
merged 45 commits into from
Apr 6, 2023

Conversation

brianchristopherbrady
Copy link
Contributor

@brianchristopherbrady brianchristopherbrady commented Mar 27, 2023

Label

A label represents a caption for an item in a user interface.


Design Spec

Link to Label Design Spec in Figma


Engineering Spec

notes

In web components, when using the shadow DOM, it's not feasible to associate elements across the shadow DOM boundary using the traditional for attribute, since the shadow DOM creates a boundary that prevents the label element from accessing the input element's id attribute. Instead, the WC3 Label component uses the aria-labelledby attribute to associate the label element with the input element. This attribute has a value that matches the id of another element on the page, which serves as a label for the input element.

The fluent-label has several visual font size (small, medium, large) and font weight(regular, semibold) options. The fluent-label also provides appearances for required and disabled states.


Use Case

Creating a simple label element with an optional info icon and optional required state


Class: Label


Variables


Fields

Name Privacy Type Default Description
required public boolean false Specifies required styling for label
disabled public boolean false Sets disabled state for label
size public "small" "medium" "large" "medium" Specifies font size for label
weight public "regular" "semibold" "regular" Specifies font weight for label

Methods


Events


Attributes

Name Field
required required
disabled disabled
size size
weight weight

Slots

Name Description
Default slotted content for label text

Template

<slot></slot> <span part="asterisk" class="asterisk" ?hidden="${x => !x.required}">*</span>

Accessibility

W3 Label Spec


WAI-ARIA Roles, States, and Properties





Preparation


Fluent Web Component v3 v.s Fluent React 9


Component and Slot Mapping

Fluent UI React 9 Fluent Web Components 3
<Label> <fluent-label>

Additional Deltas

Fluent UI React 9 Fluent Web Components 3
Renders HTMLLabelElement HTMLElement
API HTMLLabelElement Spec HTMLElement Spec
Shadow DOM n/a uses Shadow DOM
Accessibility Uses for attribute to associate with form elements Uses aria-labelledby to associate with form elements, does not have a for attribute

:host([weight='semibold']) {
font-weight: ${fontWeightSemibold};
}
:host([weight='semibold']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicated

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 27, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3da8c8b:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

* @remarks
* HTML Attribute: size
*/
@attr({ attribute: 'size' })
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to decorate @attr with attribute property unless the display attribute names is different from the property.

So this can just be

@attr
public size: LabelSize = LabelSize.medium;

* @remarks
* HTML Attribute: weight
*/
@attr({ attribute: 'weight' })
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

required="${(attr: Label) => attr.required}"
size="${(attr: Label) => attr.size}"
weight="${(attr: Label) => attr.weight}"
id="${(attr: Label) => attr.id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to bind these on on the template.

Copy link
Member

@chrisdholt chrisdholt left a comment

Choose a reason for hiding this comment

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

Would be good to have @miroslavstastny look over this as well just to be sure I didn't miss anything.

@brianchristopherbrady brianchristopherbrady changed the title Label Web Component WC3 Label Apr 5, 2023
@chrisdholt chrisdholt changed the title WC3 Label Add Label as a new web component Apr 5, 2023
@brianchristopherbrady brianchristopherbrady changed the title Add Label as a new web component WC3 Label Apr 5, 2023
@brianchristopherbrady brianchristopherbrady changed the title WC3 Label Adds Label as a new web component Apr 6, 2023
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat(label): adds Label as a new web component",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"comment": "feat(label): adds Label as a new web component",
"comment": "feat(label): add label as a new web component",

export function labelTemplate<T extends Label>(): ElementViewTemplate<T> {
return html<T>`
<slot></slot>
<span part="asterisk" class="asterisk" ?hidden="${x => !x.required}">*</span>
Copy link
Member

Choose a reason for hiding this comment

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

Just for me to learn - is it better to use hidden attribute than conditionally rendering the span?

@brianchristopherbrady brianchristopherbrady merged commit 48980fe into web-components-v3 Apr 6, 2023
@khmakoto khmakoto deleted the user/brianbrady/label branch April 11, 2023 20:44
chrisdholt added a commit that referenced this pull request Apr 29, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request Apr 30, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 2, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 2, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 2, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 3, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 6, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 6, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 8, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
radium-v pushed a commit that referenced this pull request May 10, 2024
* label init

* merge web-components-v3

* updates readme

* updates styles

* adds label styles

* removes dead import

* divides accordion and accordion item readme

* updates label docs

* updates label template

* updates label template and styles

* updates label stories

* label updates per review

* removes attr decorator on label

* label: yarn change

* radio: updates attribute story names

* label: removes attribute binding on template

* label: removes template tag

* label: updates per review

* label: adds export to root json

* adds disabled attr

* removes dead code

* Update change/@fluentui-web-components-2b95d12e-1c42-47e8-88da-aa67dac5673b.json

Co-authored-by: Chris Holt <chhol@microsoft.com>

* label: removes dead import, updates storybook args to use consts

* label: removes dead imports

* label: updates asterisk styling

* label:docs: enumerates rendered element API difs between FUIRv9 and FUIWC3

* label: updates docs

* label: fixes mispelling in docs

* label: updates template, docs

* label: updates docs

* label: replaces arg values with label options const

---------

Co-authored-by: Chris Holt <chhol@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants