Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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

"type": "minor",
"comment": "feat: add defaultindeterminate attribute to checkbox to support declarative scenarios",
"packageName": "@fluentui/web-components",
"email": "13071055+chrisdholt@users.noreply.github.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions packages/web-components/docs/web-components.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,13 @@ export type ButtonType = ValuesOf<typeof ButtonType>;
// @public
export class Checkbox extends BaseCheckbox {
constructor();
// @internal
clickHandler(e: MouseEvent): boolean | void;
defaultIndeterminate?: boolean;
// @internal
protected defaultIndeterminateChanged(prev: boolean | undefined, next: boolean | undefined): void;
// @internal
formResetCallback(): void;
indeterminate?: boolean;
// @internal
protected indeterminateChanged(prev: boolean | undefined, next: boolean | undefined): void;
Expand Down
144 changes: 144 additions & 0 deletions packages/web-components/src/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,136 @@ test.describe('Checkbox', () => {
await expect(element).toHaveJSProperty('indeterminate', false);
});

test('should initialize `defaultIndeterminate` and `indeterminate` from the `defaultindeterminate` attribute', async ({
fastPage,
}) => {
const { element } = fastPage;

await fastPage.setTemplate({ attributes: { defaultindeterminate: true } });

await expect(element).toHaveJSProperty('defaultIndeterminate', true);
await expect(element).toHaveJSProperty('indeterminate', true);
});

test('should reflect `defaultindeterminate` to `defaultIndeterminate`', async ({ fastPage }) => {
const { element } = fastPage;

await fastPage.setTemplate();

await expect(element).toHaveJSProperty('defaultIndeterminate', undefined);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', true);
});

await expect(element).toHaveJSProperty('defaultIndeterminate', true);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', false);
});

await expect(element).toHaveJSProperty('defaultIndeterminate', false);
});

test('should update live `indeterminate` from `defaultindeterminate` before user interaction', async ({
fastPage,
}) => {
const { element } = fastPage;

await fastPage.setTemplate();

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', true);
});

await expect(element).toHaveJSProperty('defaultIndeterminate', true);
await expect(element).toHaveJSProperty('indeterminate', true);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', false);
});

await expect(element).toHaveJSProperty('defaultIndeterminate', false);
await expect(element).toHaveJSProperty('indeterminate', false);
});

test('should preserve live `indeterminate` after user interaction when `defaultindeterminate` changes', async ({
fastPage,
}) => {
const { element } = fastPage;

await fastPage.setTemplate({ attributes: { defaultindeterminate: true } });

await expect(element).toHaveJSProperty('indeterminate', true);

await element.click();

await expect(element).toHaveJSProperty('indeterminate', false);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', false);
});

await expect(element).toHaveJSProperty('indeterminate', false);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', true);
});

await expect(element).toHaveJSProperty('indeterminate', false);
});

test.describe('dirty-state styling', () => {
test.skip(({ ssr }) => ssr === true, 'Dirty-state styling requires client-side user interaction.');

test('should stop applying declarative indeterminate styling after user interaction', async ({ fastPage }) => {
const { element } = fastPage;
const indeterminateIndicator = element.locator('.indeterminate-indicator');
const transparent = 'rgba(0, 0, 0, 0)';

await fastPage.setTemplate({ attributes: { defaultindeterminate: true } });

await expect(indeterminateIndicator).not.toHaveCSS('background-color', transparent);

await element.click();

await expect(element).toHaveJSProperty('indeterminate', false);
await expect(indeterminateIndicator).toHaveCSS('background-color', transparent);
});
});

test('should reset live `indeterminate` to `true` when `defaultindeterminate` is present', async ({
fastPage,
page,
}) => {
const { element } = fastPage;
const form = page.locator('form');

await fastPage.setTemplate(/* html */ `
<form>
<${tagName} defaultindeterminate></${tagName}>
</form>
`);

await expect(element).toHaveJSProperty('indeterminate', true);

await element.click();

await expect(element).toHaveJSProperty('indeterminate', false);

await form.evaluate((node: HTMLFormElement) => {
node.reset();
});

await expect(element).toHaveJSProperty('indeterminate', true);

await element.evaluate((node: Checkbox) => {
node.toggleAttribute('defaultindeterminate', false);
});

await expect(element).toHaveJSProperty('indeterminate', false);
});

test('should NOT change the `indeterminate` property when the owning form is reset', async ({ fastPage, page }) => {
const { element } = fastPage;
const form = page.locator('form');
Expand Down Expand Up @@ -188,6 +318,20 @@ test.describe('Checkbox', () => {
});
});

test('should resolve `checked` and `defaultindeterminate` independently on activation', async ({ fastPage }) => {
const { element } = fastPage;

await fastPage.setTemplate({ attributes: { checked: true, defaultindeterminate: true } });

await expect(element).toHaveJSProperty('checked', true);
await expect(element).toHaveJSProperty('indeterminate', true);

await element.click();

await expect(element).toHaveJSProperty('indeterminate', false);
await expect(element).toHaveJSProperty('checked', false);
});

test('should initialize to the provided `value` attribute when set pre-connection', async ({ fastPage, page }) => {
const expectedValue = 'foobar';

Expand Down
47 changes: 47 additions & 0 deletions packages/web-components/src/checkbox/checkbox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { argTypes } = getStorybookHelpers<FluentCheckbox>('fluent-checkbox');
const storyTemplate = html<StoryArgs<FluentCheckbox>>`
<fluent-checkbox
?checked="${story => story.checked}"
?defaultindeterminate="${story => story.defaultIndeterminate}"
?disabled="${story => story.disabled}"
id="${story => story.id}"
:indeterminate="${story => story.indeterminate}"
Expand Down Expand Up @@ -105,6 +106,33 @@ export const Indeterminate: Story = {
},
};

export const DefaultIndeterminate: Story = {
render: renderComponent(html<StoryArgs<FluentCheckbox>>`
${repeat(story => story.storyContent, html<StoryArgs<FluentCheckbox>>`${fieldStoryTemplate}<br />`)}
`),
args: {
storyContent: [
{
storyContent: storyTemplate,
defaultIndeterminate: true,
id: uniqueId('checkbox-'),
label: 'Default indeterminate',
labelPosition: LabelPosition.after,
slot: 'input',
},
{
storyContent: storyTemplate,
defaultIndeterminate: true,
id: uniqueId('checkbox-'),
label: 'Default indeterminate circular',
labelPosition: LabelPosition.after,
shape: CheckboxShape.circular,
slot: 'input',
},
],
},
};

export const Disabled: Story = {
render: renderComponent(html<StoryArgs<FluentCheckbox>>`
${repeat(story => story.storyContent, html<StoryArgs<FluentCheckbox>>`${fieldStoryTemplate}<br />`)}
Expand Down Expand Up @@ -166,6 +194,25 @@ export const Disabled: Story = {
shape: CheckboxShape.circular,
slot: 'input',
},
{
storyContent: storyTemplate,
defaultIndeterminate: true,
disabled: true,
id: uniqueId('checkbox-'),
label: 'Disabled default indeterminate',
labelPosition: LabelPosition.after,
slot: 'input',
},
{
storyContent: storyTemplate,
defaultIndeterminate: true,
disabled: true,
id: uniqueId('checkbox-'),
label: 'Disabled circular default indeterminate',
labelPosition: LabelPosition.after,
shape: CheckboxShape.circular,
slot: 'input',
},
],
},
};
Expand Down
27 changes: 20 additions & 7 deletions packages/web-components/src/checkbox/checkbox.styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@
}

:host(:state(checked)),
:host(:state(indeterminate)) {
:host(
:is(:state(indeterminate), [defaultindeterminate]:not(:state(dirty-indeterminate))):not(:is([disabled], :disabled))
) {
border-color: var(--colorCompoundBrandStroke);
}

:host(:state(checked)),
:host(:state(indeterminate)) .indeterminate-indicator {
:host(:state(indeterminate)) .indeterminate-indicator,
:host([defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked))) .indeterminate-indicator {
background-color: var(--colorCompoundBrandBackground);
}

:host(:state(indeterminate)) .indeterminate-indicator {
:host(:state(indeterminate)) .indeterminate-indicator,
:host([defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked))) .indeterminate-indicator {
border-radius: var(--borderRadiusSmall);
position: absolute;
width: calc(var(--size) / 2);
Expand Down Expand Up @@ -119,7 +123,9 @@
cursor: unset;
}

:host(:is([disabled], :disabled):state(indeterminate)) .indeterminate-indicator {
:host(:is([disabled], :disabled):state(indeterminate)) .indeterminate-indicator,
:host(:is([disabled], :disabled)[defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked)))
.indeterminate-indicator {
background-color: var(--colorNeutralStrokeDisabled);
}

Expand Down Expand Up @@ -148,20 +154,27 @@
}

:host(:state(checked)),
:host(:state(indeterminate)) .indeterminate-indicator {
:host(:state(indeterminate)) .indeterminate-indicator,
:host([defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked))) .indeterminate-indicator {
background-color: FieldText;
}

:host(:state(checked):not(:is([disabled], :disabled)):hover),
:host(:state(indeterminate):not(:is([disabled], :disabled)):hover) .indeterminate-indicator {
:host(:state(indeterminate):not(:is([disabled], :disabled)):hover) .indeterminate-indicator,
:host(
[defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked)):not(:is([disabled], :disabled)):hover
)
.indeterminate-indicator {
background-color: Highlight;
}

:host(:is([disabled], :disabled)) {
border-color: GrayText;
}

:host(:is([disabled], :disabled):state(indeterminate)) .indeterminate-indicator {
:host(:is([disabled], :disabled):state(indeterminate)) .indeterminate-indicator,
:host(:is([disabled], :disabled)[defaultindeterminate]:not(:state(dirty-indeterminate)):not(:state(checked)))
.indeterminate-indicator {
background-color: GrayText;
}

Expand Down
32 changes: 24 additions & 8 deletions packages/web-components/src/checkbox/checkbox.styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { css } from '@microsoft/fast-element';
import { checkedState, indeterminateState, nativeDisabledState } from '../styles/states/index.js';
import {
checkedState,
dirtyIndeterminateState,
indeterminateState,
nativeDisabledState,
} from '../styles/states/index.js';
import {
borderRadiusCircular,
borderRadiusMedium,
Expand Down Expand Up @@ -105,16 +110,20 @@ export const styles = css`
}

:host(${checkedState}),
:host(${indeterminateState}) {
:host(
:is(${indeterminateState}, [defaultindeterminate]:not(${dirtyIndeterminateState})):not(${nativeDisabledState})
) {
border-color: ${colorCompoundBrandStroke};
}

:host(${checkedState}),
:host(${indeterminateState}) .indeterminate-indicator {
:host(${indeterminateState}) .indeterminate-indicator,
:host([defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState})) .indeterminate-indicator {
background-color: ${colorCompoundBrandBackground};
}

:host(${indeterminateState}) .indeterminate-indicator {
:host(${indeterminateState}) .indeterminate-indicator,
:host([defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState})) .indeterminate-indicator {
border-radius: ${borderRadiusSmall};
position: absolute;
width: calc(var(--size) / 2);
Expand Down Expand Up @@ -145,7 +154,9 @@ export const styles = css`
cursor: unset;
}

:host(${nativeDisabledState}${indeterminateState}) .indeterminate-indicator {
:host(${nativeDisabledState}${indeterminateState}) .indeterminate-indicator,
:host(${nativeDisabledState}[defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState}))
.indeterminate-indicator {
background-color: ${colorNeutralStrokeDisabled};
}

Expand Down Expand Up @@ -174,20 +185,25 @@ export const styles = css`
}

:host(${checkedState}),
:host(${indeterminateState}) .indeterminate-indicator {
:host(${indeterminateState}) .indeterminate-indicator,
:host([defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState})) .indeterminate-indicator {
background-color: FieldText;
}

:host(${checkedState}:not(${nativeDisabledState}):hover),
:host(${indeterminateState}:not(${nativeDisabledState}):hover) .indeterminate-indicator {
:host(${indeterminateState}:not(${nativeDisabledState}):hover) .indeterminate-indicator,
:host([defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState}):not(${nativeDisabledState}):hover)
.indeterminate-indicator {
background-color: Highlight;
}

:host(${nativeDisabledState}) {
border-color: GrayText;
}

:host(${nativeDisabledState}${indeterminateState}) .indeterminate-indicator {
:host(${nativeDisabledState}${indeterminateState}) .indeterminate-indicator,
:host(${nativeDisabledState}[defaultindeterminate]:not(${dirtyIndeterminateState}):not(${checkedState}))
.indeterminate-indicator {
background-color: GrayText;
}

Expand Down
Loading
Loading