Skip to content

feat: add defaultindeterminate attribute to checkbox for setting indeterminate declaratively - #36514

Open
Chris Holt (chrisdholt) wants to merge 1 commit into
microsoft:masterfrom
chrisdholt:users/chhol/add-defaultindeterminate-attribute
Open

feat: add defaultindeterminate attribute to checkbox for setting indeterminate declaratively#36514
Chris Holt (chrisdholt) wants to merge 1 commit into
microsoft:masterfrom
chrisdholt:users/chhol/add-defaultindeterminate-attribute

Conversation

@chrisdholt

Copy link
Copy Markdown
Member

Previous Behavior

On the HTML Platform there is currently no way to have indeterminate exist at runtime without hydration, this issue also exists with the current Fluent checkbox.

New Behavior

This PR proposes a new defaultindeterminate attribute to support setting indeterminate declaratively. The proposed approach follows the discussion and direction provided in whatwg.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

📊 Bundle size report

✅ No changes found

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Pull request demo site: URL

@@ -0,0 +1,7 @@
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-web-components/Accordion 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-web-components/Accordion. - Dark Mode.normal.chromium_1.png 3398 Changed

*
* @internal
*/
private dirtyIndeterminate: boolean = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is dirtyIndeterminate needed? Couldn't it just piggyback onto dirtyChecked?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We might be able to.

}

this.dirtyIndeterminate = true;
toggleState(this.elementInternals, 'dirty-indeterminate', true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a true need for a dirty-indeterminate state? We don't have a separate state for dirty-checked.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is a reason for this, and I think it's one-of-a-kind situation (maybe I missed something simpler). Consider the lifecycle of defaultindeterminate.

  1. A server-rendered indeterminate means we hook off the attribute for initial visual styling (avoid using states which should be client-side only). The checkbox appears as indeterminate.
  2. Click the checkbox => checkbox shows checked and no longer indeterminate, attribute styling is preserved for defaultindeterminate
  3. Click the checkbox again => checkbox is unchecked, attribute styling is preserved for defaultindeterminate

We need to preserve the attribute that's passed from the client (we should not remove this or toggle upon user interaction). We need a way to essentially say, "This is no longer indeterminate" while preserving the attribute from user-land. I chose a state here because it explicitly applies client-side.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm open to naming on the state, but absent another solution it seems the most elegant to address what is purely a styling problem post-user-interaction.

* @remarks
* HTML Attribute: `defaultindeterminate`
*/
@attr({ attribute: 'defaultindeterminate', mode: 'boolean' })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why defaultindeterminate? We don't use defaultchecked or defaultdisabled as attribute names. Since indeterminate doesn't yet exist as an attribute, can't that be used, while still mapping it to the defaultIndeterminate property?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because reusing indeterminate is not the direction the platform is most likely to go. indeterminate would suffer the same issue that checked does where there is increased cognitive load and confusion as it only pertains to the initial state. See the discussion here which is referenced in the issue: whatwg/html#6578

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants