Skip to content

Commit

Permalink
fix(fluent-button): fix typo in compound disabled selector, add tests (
Browse files Browse the repository at this point in the history
…#31302)

Co-authored-by: Chris Holt <13071055+chrisdholt@users.noreply.github.com>
  • Loading branch information
davatron5000 and chrisdholt committed May 16, 2024
1 parent 30e870e commit fa9416a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix compound disabled selector in fluent-button and fluent-anchor-button",
"packageName": "@fluentui/web-components",
"email": "rupertdavid@microsoft.com",
"dependentChangeType": "patch"
}
18 changes: 18 additions & 0 deletions packages/web-components/src/anchor-button/anchor-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,22 @@ test.describe('Anchor Button - Boolean Attributes', () => {
await expect(element).toHaveJSProperty(attribute, value);
});
}

test(`should have transparent border when the \`disabled\` or \`disabled-focus\` attribute is present`, async ({
page,
}) => {
await element.evaluate((node: any) => {
node.setAttribute('appearance', 'primary');
node.setAttribute('disabled', true);
});

await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)');

await element.evaluate((node: any) => {
node.setAttribute('disabled', false); // Reset
node.setAttribute('disabled-focusable', true);
});

await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)');
});
});
25 changes: 13 additions & 12 deletions packages/web-components/src/anchor-button/anchor-button.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ export const styles = css`
box-shadow: ${shadow2}, 0 0 0 2px ${colorStrokeFocus2};
}
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"])) .control,
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"]):hover) .control,
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"]):hover:active) .control {
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary'])) .control,
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary']):hover) .control,
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary']):hover:active) .control {
border-color: transparent;
}
Expand All @@ -234,9 +234,9 @@ export const styles = css`
background-color: ${colorTransparentBackgroundPressed};
}
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"])) .control,
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"]):hover) .control,
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"]):hover:active) .control {
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline'])) .control,
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline']):hover) .control,
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline']):hover:active) .control {
background-color: ${colorTransparentBackground};
}
Expand All @@ -258,9 +258,9 @@ export const styles = css`
border-color: transparent;
}
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"])) .control,
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"]):hover) .control,
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"]):hover:active) .control {
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle'])) .control,
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle']):hover) .control,
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle']):hover:active) .control {
background-color: ${colorTransparentBackground};
border-color: transparent;
}
Expand Down Expand Up @@ -294,9 +294,10 @@ export const styles = css`
border-color: transparent;
}
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"])) .control,
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"]):hover) .control,
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"]):hover:active) .control {
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent'])) .control,
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent']):hover) .control,
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent']):hover:active)
.control {
border-color: transparent;
background-color: ${colorTransparentBackground};
}
Expand Down
20 changes: 20 additions & 0 deletions packages/web-components/src/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ test.describe('Button', () => {
await expect(element).not.toBeFocused();
});

test('should have transparent border when the `disabled` attribute is present', async ({ page }) => {
const element = page.locator('fluent-button');

await page.setContent(/* html */ `
<fluent-button appearance='primary' disabled>Button</fluent-button>
`);

await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)');
});

test('should be focusable when the `disabled-focusable` attribute is present', async ({ page }) => {
const element = page.locator('fluent-button');

Expand All @@ -116,6 +126,16 @@ test.describe('Button', () => {
await expect(element).toBeFocused();
});

test('should have transparent border when the `disabled-focusable` attribute is present', async ({ page }) => {
const element = page.locator('fluent-button');

await page.setContent(/* html */ `
<fluent-button appearance='primary' disabled-focusable>Button</fluent-button>
`);

await expect(element).toHaveCSS('border-color', 'rgb(0, 0, 0)');
});

test('should NOT be clickable when the `disabled` attribute is present', async ({ page }) => {
const element = page.locator('fluent-button');

Expand Down
24 changes: 12 additions & 12 deletions packages/web-components/src/button/button.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ export const styles = css`
box-shadow: ${shadow2}, 0 0 0 2px ${colorStrokeFocus2};
}
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"])),
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"]):hover),
:host(is:([disabled][appearance='primary'], [disabled-focusabale][appearance="primary"]):hover:active) {
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary'])),
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary']):hover),
:host(:is([disabled][appearance='primary'], [disabled-focusabale][appearance='primary']):hover:active) {
border-color: transparent;
}
Expand All @@ -231,9 +231,9 @@ export const styles = css`
background-color: ${colorTransparentBackgroundPressed};
}
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"])),
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"]):hover),
:host(is:([disabled][appearance='outline'], [disabled-focusabale][appearance="outline"]):hover:active) {
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline'])),
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline']):hover),
:host(:is([disabled][appearance='outline'], [disabled-focusabale][appearance='outline']):hover:active) {
background-color: ${colorTransparentBackground};
}
Expand All @@ -255,9 +255,9 @@ export const styles = css`
border-color: transparent;
}
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"])),
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"]):hover),
:host(is:([disabled][appearance='subtle'], [disabled-focusabale][appearance="subtle"]):hover:active) {
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle'])),
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle']):hover),
:host(:is([disabled][appearance='subtle'], [disabled-focusabale][appearance='subtle']):hover:active) {
background-color: ${colorTransparentBackground};
border-color: transparent;
}
Expand Down Expand Up @@ -291,9 +291,9 @@ export const styles = css`
border-color: transparent;
}
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"])),
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"]):hover),
:host(is:([disabled][appearance='transparent'], [disabled-focusabale][appearance="transparent"]):hover:active) {
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent'])),
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent']):hover),
:host(:is([disabled][appearance='transparent'], [disabled-focusabale][appearance='transparent']):hover:active) {
border-color: transparent;
background-color: ${colorTransparentBackground};
}
Expand Down

0 comments on commit fa9416a

Please sign in to comment.