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

feat(a11y): give RadioGroup aria "radiogroup" role #6940

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
73a0519
add changelog entry
bvandercar-vt Jun 25, 2024
7c7083d
Merge branch 'develop' of https://github.com/palantir/blueprint into …
bvandercar-vt Aug 7, 2024
5c7812a
Merge branch 'develop' of https://github.com/palantir/blueprint into …
bvandercar-vt Aug 8, 2024
4f9970c
feat(a11y): give RadioGroup aria "radiogroup" role
bvandercar-vt Aug 12, 2024
7121447
remove commit
bvandercar-vt Aug 12, 2024
3fb2e7c
allow any aria attributes
bvandercar-vt Aug 12, 2024
12c8aa9
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Sep 10, 2024
a2d0b7d
revert style change
bvandercar-vt Sep 10, 2024
dd91e52
allow all HTMLDivProps
bvandercar-vt Sep 10, 2024
7ecdc25
add selectedValue to INVALID_PROPS
bvandercar-vt Sep 10, 2024
1d857d6
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Sep 13, 2024
dd311e1
style: comment
bvandercar-vt Sep 13, 2024
130fd09
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Sep 17, 2024
3c3ea8b
Merge branch 'develop' of https://github.com/palantir/blueprint into …
bvandercar-vt Sep 18, 2024
579ff4d
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Sep 18, 2024
d17671e
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Sep 23, 2024
e2065cd
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Oct 3, 2024
7215c46
alpha order
bvandercar-vt Oct 3, 2024
f26ab69
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Nov 5, 2024
23484d0
Merge branch 'develop' into bvandercar/a11y/radiogroup-role
bvandercar-vt Nov 7, 2024
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
1 change: 1 addition & 0 deletions packages/core/src/common/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const INVALID_PROPS = [
"rightElement",
"rightIcon",
"round",
"selectedValue",
"size",
"small",
"tagName",
Expand Down
34 changes: 27 additions & 7 deletions packages/core/src/components/forms/radioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@
import classNames from "classnames";
import * as React from "react";

import { AbstractPureComponent, Classes, DISPLAYNAME_PREFIX, type OptionProps, type Props } from "../../common";
import {
AbstractPureComponent,
Classes,
DISPLAYNAME_PREFIX,
type HTMLDivProps,
type OptionProps,
type Props,
removeNonHTMLProps,
} from "../../common";
import * as Errors from "../../common/errors";
import { isElementOfType } from "../../common/utils";
import { isElementOfType, uniqueId } from "../../common/utils";
import { RadioCard } from "../control-card/radioCard";

import type { ControlProps } from "./controlProps";
import { Radio, type RadioProps } from "./controls";

export interface RadioGroupProps extends Props {
export interface RadioGroupProps extends Props, HTMLDivProps {
/**
* Radio elements. This prop is mutually exclusive with `options`.
* If passing custom children, ensure options have `role="radio"` or
* `input` with `type="radio"`.
*/
children?: React.ReactNode;

Expand Down Expand Up @@ -86,11 +96,21 @@ export class RadioGroup extends AbstractPureComponent<RadioGroupProps> {
private autoGroupName = nextName();

public render() {
const { label } = this.props;
const { disabled, label, options, className, children, name, onChange, ...htmlProps } = this.props;
const labelId = uniqueId("label");
return (
<div className={classNames(Classes.RADIO_GROUP, this.props.className)}>
{label == null ? null : <label className={Classes.LABEL}>{label}</label>}
{Array.isArray(this.props.options) ? this.renderOptions() : this.renderChildren()}
<div
role="radiogroup"
aria-labelledby={label ? labelId : undefined}
{...removeNonHTMLProps(htmlProps)}
className={classNames(Classes.RADIO_GROUP, className)}
>
{label && (
<label className={Classes.LABEL} id={labelId}>
{label}
</label>
)}
{Array.isArray(options) ? this.renderOptions() : this.renderChildren()}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const SegmentedControl: React.FC<SegmentedControlProps> = React.forwardRe
if (role === "radiogroup") {
// in a `radiogroup`, arrow keys select next item, not tab key.
const direction = Utils.getArrowKeyDirection(e, ["ArrowLeft", "ArrowUp"], ["ArrowRight", "ArrowDown"]);
const { current: outerElement } = outerRef;
const outerElement = outerRef.current;
if (direction === undefined || !outerElement) return;

const focusedElement = Utils.getActiveElement(outerElement)?.closest<HTMLButtonElement>("button");
Expand Down