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(Dropdown): Enhance accessibility by exposing combobox role directly to the span label (Fixes #7584) #7585

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions components/doc/dropdown/accessibilitydoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export function AccessibilityDoc() {
const code = {
basic: `
<span id="dd1">Options</span>
<Dropdown aria-labelledby="dd1" />
<Dropdown ariaLabelledby="dd1" />

<Dropdown aria-label="Options" />
<Dropdown ariaLabel="Options" />
`
};

Expand Down
14 changes: 8 additions & 6 deletions components/doc/dropdown/floatlabeldoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default function FloatLabelDemo() {
return (
<div className="card flex justify-content-center">
<FloatLabel className="w-full md:w-14rem">
<Dropdown inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
<label htmlFor="dd-city">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
<label htmlFor="dd-city" id="dd-city-label">Select a City</label>
</FloatLabel>
</div>
)
Expand Down Expand Up @@ -69,8 +69,8 @@ export default function FloatLabelDemo() {
return (
<div className="card flex justify-content-center">
<FloatLabel className="w-full md:w-14rem">
<Dropdown inputId="dd-city" value={selectedCity} onChange={(e: DropdownChangeEvent) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
<label htmlFor="dd-city">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e: DropdownChangeEvent) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
<label htmlFor="dd-city" id="dd-city-label">Select a City</label>
</FloatLabel>
</div>
)
Expand All @@ -85,8 +85,10 @@ export default function FloatLabelDemo() {
</DocSectionText>
<div className="card flex justify-content-center">
<FloatLabel className="w-full md:w-14rem">
<Dropdown inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
<label htmlFor="dd-city">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-floatlabel" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" showClear className="w-full" />
<label htmlFor="dd-city" id="dd-city-floatlabel">
Select a City
</label>
</FloatLabel>
</div>
<DocSectionCode code={code} />
Expand Down
97 changes: 97 additions & 0 deletions components/doc/dropdown/labeldoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { DocSectionCode } from '@/components/doc/common/docsectioncode';
import { DocSectionText } from '@/components/doc/common/docsectiontext';
import { Dropdown } from '@/components/lib/dropdown/Dropdown';
import { useState } from 'react';

export function LabelDoc(props) {
const [selectedCity, setSelectedCity] = useState(null);
const cities = [
{ name: 'New York', code: 'NY' },
{ name: 'Rome', code: 'RM' },
{ name: 'London', code: 'LDN' },
{ name: 'Istanbul', code: 'IST' },
{ name: 'Paris', code: 'PRS' }
];

const code = {
basic: `
<div>
<label htmlFor="dd-city" id="dd-city-label">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
</div>
`,
javascript: `
import React, { useState } from "react";
import { Dropdown } from 'primereact/dropdown';

export default function FloatLabelDemo() {
const [selectedCity, setSelectedCity] = useState(null);
const cities = [
{ name: 'New York', code: 'NY' },
{ name: 'Rome', code: 'RM' },
{ name: 'London', code: 'LDN' },
{ name: 'Istanbul', code: 'IST' },
{ name: 'Paris', code: 'PRS' }
];

return (
<div className="card flex justify-content-center">
<div className="w-full md:w-14rem">
<label htmlFor="dd-city" id="dd-city-label">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
</div>
</div>
)
}
`,
typescript: `
import React, { useState } from "react";
import { Dropdown, DropdownChangeEvent } from 'primereact/dropdown';
import { div } from 'primereact/floatlabel';

interface City {
name: string;
code: string;
}

export default function FloatLabelDemo() {
const [selectedCity, setSelectedCity] = useState<City | null>(null);
const cities: City[] = [
{ name: 'New York', code: 'NY' },
{ name: 'Rome', code: 'RM' },
{ name: 'London', code: 'LDN' },
{ name: 'Istanbul', code: 'IST' },
{ name: 'Paris', code: 'PRS' }
];

return (
<div className="card flex justify-content-center">
<div className="w-full md:w-14rem">
<label htmlFor="dd-city" id="dd-city-label">Select a City</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e: DropdownChangeEvent) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
</div>
</div>
)
}
`
};

return (
<>
<DocSectionText {...props}>
<p>
Dropdown associated with a label using the <i>aria-labelledby</i> property and the label element's <i>id</i> attribute.
</p>
</DocSectionText>
<div className="card flex justify-content-center">
<div className="w-full md:w-14rem">
<label className="px-2" htmlFor="dd-city" id="dd-city-label">
Select a City
</label>
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" />
</div>
</div>
<DocSectionCode code={code} />
</>
);
}
Loading
Loading