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

A11y revamp: Pharos buttons (non-breaking change) #628

Merged
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
641bf37
docs: add @sirrah-tam as a contributor
sirrah-tam Sep 6, 2023
b5f9432
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Sep 11, 2023
8ef3b14
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Sep 16, 2023
c05512c
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Sep 18, 2023
4d9d486
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Sep 27, 2023
c352e45
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Sep 29, 2023
a92d4d8
feat(button): add a11y naming convention for aria
sirrah-tam Oct 3, 2023
e93a491
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 3, 2023
ceeb435
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 4, 2023
b49e476
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 5, 2023
b86feab
feat(button): add aria-description support
sirrah-tam Oct 5, 2023
8ea7983
chore: add changset
sirrah-tam Oct 5, 2023
ae3ffb9
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 12, 2023
3f9ec2a
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Oct 12, 2023
c21f585
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 16, 2023
9ad5501
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Oct 16, 2023
e0a2973
Merge remote-tracking branch 'ithaka/develop' into feature/non-breaki…
sirrah-tam Oct 18, 2023
2760f7d
Update packages/pharos/src/components/button/pharos-button.ts
sirrah-tam Oct 18, 2023
d8eac20
Update packages/pharos/src/components/button/pharos-button.ts
sirrah-tam Oct 18, 2023
778184f
Merge branch 'feature/non-breaking-a11y-button' of github.com:sirrah-…
sirrah-tam Oct 18, 2023
1f86625
feat(button): move property deprecated flag
sirrah-tam Oct 18, 2023
f3a8fe4
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 18, 2023
5a7e610
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Oct 24, 2023
49a37d3
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Oct 24, 2023
0c04784
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Nov 2, 2023
5dc8c3e
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Nov 3, 2023
5bdecf1
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Nov 3, 2023
1f29064
Merge branch 'develop' of github.com:ithaka/pharos into develop
sirrah-tam Nov 15, 2023
73075e5
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Nov 15, 2023
f3409af
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Nov 30, 2023
269201f
Merge branch 'develop' into feature/non-breaking-a11y-button
sirrah-tam Dec 5, 2023
2dd0e9c
fix(button): remove ts-ignore after lit upgrade
sirrah-tam Dec 5, 2023
561de92
feat(button): add a11y state typing
sirrah-tam Dec 5, 2023
50ee900
fix: add TODO for future reference
sirrah-tam Dec 5, 2023
45d2180
fix(a11y attributes): update AriaHiddenState name
sirrah-tam Dec 8, 2023
b1779ec
Merge branch 'feature/non-breaking-a11y-button' of github.com:sirrah-…
sirrah-tam Dec 8, 2023
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
5 changes: 5 additions & 0 deletions .changeset/large-frogs-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ithaka/pharos': minor
---

Update PharosButton to use a11y naming convention and include wider ARIA support
68 changes: 60 additions & 8 deletions packages/pharos/src/components/button/pharos-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export type ButtonType = 'button' | 'submit' | 'reset';

export type ButtonVariant = 'primary' | 'secondary' | 'subtle' | 'overlay';

// undefined means no state has been expressed at all and won't render; 'undefined' is an explicit state
export type PressedState = 'false' | 'true' | 'mixed' | 'undefined' | undefined;

const TYPES = ['button', 'submit', 'reset'] as ButtonType[];

const VARIANTS = ['primary', 'secondary', 'subtle', 'overlay'] as ButtonVariant[];
Expand Down Expand Up @@ -112,12 +109,41 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
public large = false;

/**
* @deprecated
brentswisher marked this conversation as resolved.
Show resolved Hide resolved
* Indicates the aria label to apply to the button.
* @attr label
*/
@property({ type: String, reflect: true })
public label?: string;

/**
* Indicates the aria label to apply to the button.
* @attr a11y-label
*/
@property({ type: String, reflect: true, attribute: 'a11y-label' })
public a11yLabel?: string;

/**
* Indicates the aria description to apply to the button.
* @attr a11y-description
*/
@property({ type: String, reflect: true, attribute: 'a11y-description' })
public a11yDescription?: string;

/**
* Indicates the aria expanded state to apply to the button.
* @attr a11y-expanded
*/
@property({ type: String, reflect: true, attribute: 'a11y-expanded' })
public a11yExpanded: AriaExpandedState = undefined;

/**
* Indicates the aria expanded state to apply to the button.
* @attr a11y-haspopup
*/
@property({ type: String, reflect: true, attribute: 'a11y-haspopup' })
public a11yHaspopup: AriaPopupState = undefined;

/**
* Indicates the button's width should match its container.
* @attr full-width
Expand All @@ -140,11 +166,19 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
public value?: string;

/**
* @deprecated
* Indicates this button is a toggle button and whether it is pressed or not.
* @attr value
*/
@property({ type: String, reflect: true })
public pressed: PressedState = undefined;
public pressed: AriaPressedState = undefined;

/**
* Indicates this button is a toggle button and whether it is pressed or not.
* @attr value
*/
@property({ type: String, reflect: true, attribute: 'a11y-pressed' })
public a11yPressed: AriaPressedState = undefined;

@query('#button-element')
private _button!: HTMLButtonElement | HTMLAnchorElement;
Expand Down Expand Up @@ -178,6 +212,14 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
`${this.variant} is not a valid variant. Valid variants are: ${VARIANTS.join(', ')}`
);
}

if (this.label) {
console.warn("The 'label' attribute is deprecated. Use 'a11y-label' instead.");
}

if (this.pressed) {
console.warn("The 'pressed' attribute is deprecated. Use 'a11y-pressed' instead.");
}
}

override connectedCallback(): void {
Expand Down Expand Up @@ -243,6 +285,10 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
}

protected override render(): TemplateResult {
// Remove in future release once sufficient time elapsed to update naming convention
sirrah-tam marked this conversation as resolved.
Show resolved Hide resolved
const a11yLabel = this.a11yLabel ?? this.label;
const a11yPressed = this.a11yPressed ?? this.pressed;

return this.href
? html`
<a
Expand All @@ -254,8 +300,11 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
ping=${ifDefined(this.ping)}
rel=${ifDefined(this.rel)}
target=${ifDefined(this.target)}
aria-label=${ifDefined(this.label)}
aria-pressed=${ifDefined(this.pressed)}
aria-label=${ifDefined(a11yLabel)}
aria-description=${ifDefined(this.a11yDescription)}
aria-pressed=${ifDefined(a11yPressed)}
aria-expanded=${ifDefined(this.a11yExpanded)}
aria-haspopup=${ifDefined(this.a11yHaspopup)}
@keyup=${this._handleKeyup}
>
${this.buttonContent}
Expand All @@ -269,8 +318,11 @@ export class PharosButton extends ScopedRegistryMixin(FocusMixin(AnchorElement))
?autofocus=${this.autofocus}
?disabled=${this.disabled}
type="${ifDefined(this.type)}"
aria-label=${ifDefined(this.label)}
aria-pressed=${ifDefined(this.pressed)}
aria-label=${ifDefined(a11yLabel)}
aria-description=${ifDefined(this.a11yDescription)}
aria-pressed=${ifDefined(a11yPressed)}
aria-expanded=${ifDefined(this.a11yExpanded)}
aria-haspopup=${ifDefined(this.a11yHaspopup)}
>
${this.buttonContent}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PharosButton } from '../button/pharos-button';
import type { PharosSidenav } from './pharos-sidenav';

import type { LinkTarget } from '../base/anchor-element';
import type { ButtonType, IconName, ButtonVariant, PressedState } from '../button/pharos-button';
export type { LinkTarget, ButtonType, IconName, ButtonVariant, PressedState };
import type { ButtonType, IconName, ButtonVariant } from '../button/pharos-button';
export type { LinkTarget, ButtonType, IconName, ButtonVariant };

/**
* Pharos sidenav button component.
Expand Down
4 changes: 2 additions & 2 deletions packages/pharos/src/components/toast/pharos-toast-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { toastButtonStyles } from './pharos-toast-button.css';
import { PharosButton } from '../button/pharos-button';

import type { LinkTarget } from '../base/anchor-element';
import type { ButtonType, IconName, ButtonVariant, PressedState } from '../button/pharos-button';
import type { ButtonType, IconName, ButtonVariant } from '../button/pharos-button';

export type { LinkTarget, ButtonType, IconName, ButtonVariant, PressedState };
export type { LinkTarget, ButtonType, IconName, ButtonVariant };

/**
* Pharos toast button component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import type { CSSResultArray, PropertyValues } from 'lit';
import { toggleButtonStyles } from './pharos-toggle-button.css';
import { PharosButton } from '../button/pharos-button';

import type {
ButtonType,
LinkTarget,
IconName,
ButtonVariant,
PressedState,
} from '../button/pharos-button';
export type { ButtonType, LinkTarget, IconName, ButtonVariant, PressedState };
import type { ButtonType, LinkTarget, IconName, ButtonVariant } from '../button/pharos-button';
export type { ButtonType, LinkTarget, IconName, ButtonVariant };

/**
* Pharos toggle button component.
Expand Down
17 changes: 17 additions & 0 deletions packages/pharos/src/typings/a11y-attributes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export {};

declare global {
type AriaHiddenValues = 'false' | 'true' | 'undefined' | undefined;
sirrah-tam marked this conversation as resolved.
Show resolved Hide resolved
type AriaPressedState = 'false' | 'true' | 'mixed' | 'undefined' | undefined;
type AriaExpandedState = 'false' | 'true' | 'undefined' | undefined;
type AriaDisabledState = 'false' | 'true' | undefined;
type AriaPopupState =
| 'false'
| 'true'
| 'menu'
| 'tree'
| 'grid'
| 'listbox'
| 'dialog'
| undefined;
}
Loading