-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Adds Label as a new web component #27344
Conversation
:host([weight='semibold']) { | ||
font-weight: ${fontWeightSemibold}; | ||
} | ||
:host([weight='semibold']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated
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:
|
* @remarks | ||
* HTML Attribute: size | ||
*/ | ||
@attr({ attribute: 'size' }) |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@@ -0,0 +1,7 @@ | |||
{ | |||
"type": "prerelease", | |||
"comment": "feat(label): adds Label as a new web component", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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> |
There was a problem hiding this comment.
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?
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
Label
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 thearia-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
required
boolean
false
disabled
boolean
false
size
"small"
"medium"
"large"
"medium"
weight
"regular"
"semibold"
"regular"
Methods
Events
Attributes
required
disabled
size
weight
Slots
Template
Accessibility
W3 Label Spec
WAI-ARIA Roles, States, and Properties
aria-labelledby
Preparation
Fluent Web Component v3 v.s Fluent React 9
Component and Slot Mapping
<Label>
<fluent-label>
Additional Deltas
HTMLLabelElement
HTMLElement
HTMLLabelElement
SpecHTMLElement
Specfor
attribute to associate with form elementsaria-labelledby
to associate with form elements, does not have afor
attribute