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

web component Radio and RadioGroup spec #26900

Conversation

brianchristopherbrady
Copy link
Contributor

@brianchristopherbrady brianchristopherbrady commented Feb 17, 2023

Radio

Radio buttons allow users to select a single option from two or more choices. Radio buttons are typically rendered as small circles, which are filled or highlighted when selected.


Design Spec

Link to Radio Design Spec in Figma


Engineering Spec

Fluent WC3 Radio is a form associated component that extends from the FAST Radio FAST Radio and is intended to be as close to the Fluent UI React 9 Menu implementation as possible. However, due to the nature of web components there will not be 100% parity between the two.

Use Case

Used anywhere an author might otherwise use an input[type="radio"]. Used to facilitate choice where only one choice is acceptable.


Class: Radio


Component Name


fluent-radio


Variables


Fields

Name Privacy Type Default Description
name public string The name of the radio. See name attribute for more info.
disabled public boolean Sets disabled state for radio
labelPosition public "after" "below" "below" The position of the label relative to the radio indicator.
checked public boolean false When true, radio button will be checked

Methods

Name Privacy Description Parameters Return Inherited From
templateChanged public void FoundationElement
stylesChanged public void FoundationElement

Events

Name Type Inherited From
change

Attributes

Name Field
name name
disabled disabled
label-position labelPosition
checked checked

Slots

Name Description
checked-indicator The checked indicator
Default slotted content for label text



Suggested Template


radioTemplate from FastFoundation




Accessibility

W3 Radio Spec


WAI-ARIA Roles, States, and Properties

Attributes value Description
role radio
aria-checked the checked state of the component
aria-required the required state of the component
aria-disabled the disabled state of the component
tabindex 0



Preparation


Fluent Web Component v3 v.s Fluent React 9


Component and Slot Mapping

Fluent UI React 9 Fluent Web Components 3
<Radio> <fluent-radio>

Property Mapping

Fluent UI React 9 Fluent Web Components 3 Description of difference
prop label default slotted content React implementation requires user to pass a string through the label prop on the Radio component

The web component implementation requires users to pass the label text through the default slotted content

Radio Group

RadioGroup lets people select a single option from two or more Radio items. Use RadioGroup to present all available choices if there's enough space. For more than 5 choices, consider using a different component such as Dropdown.


Design Spec

Link to Radio Design Spec in Figma


Engineering Spec

A radio group is a set of checkable buttons, known as radio buttons, where no more than one of the buttons can be checked at a time. Some implementations may initialize the set with all buttons in the unchecked state in order to force the user to check one of the buttons before moving past a certain point in the workflow.

Use Case

Radio group allows the user to be presented with a list of all the options visible which can facilitate the comparison of choice.


Class: RadioGroup


Component Name


fluent-radio-group


Fields

Name Privacy Type Default Description
disabled public boolean false Disables the radio group and child radios.
name public string The name of the radio group. Setting this value will set the name value for all child radio elements.
value public string The value of the checked radio.
orientation public horizontal | vertical horizontal The orientation of the group
childItems public HTMLElement[] The orientation of the group

Methods

Name Privacy Description Parameters Return Inherited From
nameChanged protected void
valueChanged protected void
templateChanged protected void
stylesChanged protected void

Events

Name Type Description
change Fires a custom 'change' event when the value changes

Attributes

Name Field Inherited From
disabled disabled
named name
value value
orientation orientation

Slots

Name Description
The default slotted content
label Provide label for the radio group



Suggested Template

radioGroupTemplate from FastFoundation

Accessibility

W3 Radio Spec


WAI-ARIA Roles, States, and Properties

Attributes value Description
aria-labelledby used to associate a label with the group



Preparation


Fluent Web Component v3 v.s Fluent React 9


Component and Slot Mapping

Fluent UI React 9 Fluent Web Components 3
<RadioGroup> <fluent-radio-group>

Property Mapping

Fluent UI React 9 Fluent Web Components 3 Description of difference
layout orientation React implementation requires user to pass either "horizontal" or "horizontal-stacked" through layout prop.
WC3 implementation requires user to either pass "vertical" or "horizontal" through orientation attribute.

@fabricteam
Copy link
Collaborator

fabricteam commented Feb 17, 2023

📊 Bundle size report

🤖 This report was generated against f8d5e364067660db4ab0f161ad288257ff38efa4

@size-auditor
Copy link

size-auditor bot commented Feb 17, 2023

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: f8d5e364067660db4ab0f161ad288257ff38efa4 (build)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 17, 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 82a3673:

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

@@ -0,0 +1,122 @@
# Radio
Copy link
Member

Choose a reason for hiding this comment

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

We should couple RadioGroup along with this I think. If the goal is to leverage the FAST implementation, those two go hand in hand since we implement non-native inputs. All the behavior is in RadioGroup as of now.


| Name | Privacy | Type | Default | Description |
| --------------- | ------- | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `readOnly` | public | `boolean` | | When true, the control will be immutable by user interaction. See readonly [HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) for more information. |
Copy link
Member

Choose a reason for hiding this comment

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

This is likely getting removed, we can validate, but I think it's the right move: microsoft/fast#6438

@micahgodbolt micahgodbolt removed their assignment Feb 21, 2023
@brianchristopherbrady brianchristopherbrady changed the title web component radio spec web component Radio and RadioGroup spec Feb 21, 2023
@@ -0,0 +1,127 @@
# Radio Group

> RadioGroup lets people select a single option from two or more Radio items. Use RadioGroup to present all available choices if there's enough space. For more than 5 choices, consider using a different component such as Dropdown.
Copy link
Member

Choose a reason for hiding this comment

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

Dropdown may not exist here, let's update this to not suggest using components we don't have or know will exist :).


## **Engineering Spec**

A radio group is a set of checkable buttons, known as radio buttons, where no more than one of the buttons can be checked at a time. Some implementations may initialize the set with all buttons in the unchecked state in order to force the user to check one of the buttons before moving past a certain point in the workflow.
Copy link
Member

Choose a reason for hiding this comment

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

Let's denote that this is a quote from the W3C, without that, it's written in a way where I might mistake that these should be built with buttons, which is inaccurate as the roles are different.


### Use Case

Radio group allows the user to be presented with a list of all the options visible which can facilitate the comparison of choice.
Copy link
Member

Choose a reason for hiding this comment

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

Does this accurately describe use cases?

| `name` | public | `string` | | The name of the radio group. Setting this value will set the name value for all child radio elements. |
| `value` | public | `string` | | The value of the checked radio. |
| `orientation` | public | `horizontal \| vertical` | `horizontal` | The orientation of the group |
| `childItems` | public | `HTMLElement[]` | | The orientation of the group |
Copy link
Member

Choose a reason for hiding this comment

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

What is childItems? This looks copied over, but I think this is internals... if you were to pass a property of childItems I don't think it works. IIRC, you slot the items in the default slot.

Comment on lines 53 to 54
| `templateChanged` | protected | | | `void` | |
| `stylesChanged` | protected | | | `void` | |
Copy link
Member

Choose a reason for hiding this comment

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

Do these really exist?


| Name | Description |
| ----- | --------------------------------- |
| | The default slotted content |
Copy link
Member

Choose a reason for hiding this comment

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

These aren't default slotted content - this is the default slot which expects radios


## **Accessibility**

[W3 Radio Spec](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_radio_role)
Copy link
Member

Choose a reason for hiding this comment

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

**Property Mapping**
| Fluent UI React 9 | Fluent Web Components 3 | Description of difference |
|-------------------|------------------------ |---------------------------|
| `layout` | `orientation` | React implementation requires user to pass either `"horizontal"` or `"horizontal-stacked"` through `layout` prop. <br /> WC3 implementation requires user to either pass `"vertical"` or "`horizontal"` through `orientation` attribute.
Copy link
Member

Choose a reason for hiding this comment

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

Curious of @miroslavstastny's thoughts here, but I'm not sure that layout and orientation are necessarily 1:1. I do think that it probably overlaps in terms of use case though with aria-orientation being set/updated with a change to layout. It seems like there are a couple ways we can go here...we can add a layout attribute with these values and do some aliasing to make sure if orientation isn't updated it gets updated with a change to layout, we can have a slightly different implementation where we have a boolean stacked attribute which would stack the radios (we can choose to apply only to horizontal), or we can do something else.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is outstanding but everything else seems reasonable to me

**Property Mapping**
| Fluent UI React 9 | Fluent Web Components 3 | Description of difference |
|-------------------|------------------------ |---------------------------|
| `prop label` | default slotted content | React implementation requires user to pass a string through the `label` prop on the Radio component <br /><br /> The web component implementation requires users to pass the label text through the default slotted content
Copy link
Member

Choose a reason for hiding this comment

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

nit, technically it's not required to pass the text for the label via the default slot; you could pass an aria-label or use aria-labelledby to associate it with an element outside it's slot...but the slot is the primary place where the label would go.

Comment on lines +53 to +54
| `nameChanged` | protected | | | `void` | |
| `valueChanged` | protected | | | `void` | |
Copy link
Member

Choose a reason for hiding this comment

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

just a note that while not enumerated, each attr includes a [attribute]Changed() callback 👍

@brianchristopherbrady brianchristopherbrady merged commit 9ae2455 into web-components-v3 Mar 2, 2023
@brianchristopherbrady brianchristopherbrady deleted the user/brianbrady/web-component-radio-spec branch March 2, 2023 19:00
chrisdholt pushed a commit that referenced this pull request Apr 29, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 29, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit to radium-v/fluentui that referenced this pull request Apr 30, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request Apr 30, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 2, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 3, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 6, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 6, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 8, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
radium-v pushed a commit that referenced this pull request May 10, 2024
* radio spec init

* updates radio spec formatting

* adds radio group spec

* updates radio specs

* updates spec

* yarn change
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

5 participants