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(picker-column): assign custom aria-labels to column options #26749

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions core/src/components/picker-column/picker-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export class PickerColumnCmp implements ComponentInterface {

render() {
const col = this.col;
const Button = 'button' as any;
const mode = getIonMode(this);
return (
<Host
Expand All @@ -382,9 +381,13 @@ export class PickerColumnCmp implements ComponentInterface {
)}
<div class="picker-opts" style={{ maxWidth: col.optionsWidth! }} ref={(el) => (this.optsEl = el)}>
{col.options.map((o, index) => (
<Button type="button" class={{ 'picker-opt': true, 'picker-opt-disabled': !!o.disabled }} opt-index={index}>
<button
aria-label={o.ariaLabel}
class={{ 'picker-opt': true, 'picker-opt-disabled': !!o.disabled }}
opt-index={index}
>
{o.text}
</Button>
</button>
))}
</div>
{col.suffix && (
Expand Down
47 changes: 47 additions & 0 deletions core/src/components/picker-column/test/picker-column-aria.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { h } from '@stencil/core';
import { newSpecPage } from '@stencil/core/testing';

import { PickerColumnCmp } from '../picker-column';
/**
* Stencil has an issue where having multiple spec tests in the same file,
* will cause an exception to be thrown. This test is located in a separate file
* to avoid this issue.
*
* Example exception:
* ```
* TypeError: Cannot read properties of undefined (reading '$instanceValues$')
at getValue (/Users/sean/Documents/ionic/framework-next/core/node_modules/@stencil/core/internal/testing/index.js:542:282)
sean-perkins marked this conversation as resolved.
Show resolved Hide resolved
at PickerColumnCmp.get (/Users/sean/Documents/ionic/framework-next/core/node_modules/@stencil/core/internal/testing/index.js:571:13)
at PickerColumnCmp.refresh (/Users/sean/Documents/ionic/framework-next/core/src/components/picker-column/picker-column.tsx:304:20)
at Timeout._onTimeout (/Users/sean/Documents/ionic/framework-next/core/src/components/picker-column/picker-column.tsx:73:12)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)

* ```
*/
describe('picker-column', () => {
it('should add aria-label to the picker column option', async () => {
const col = {
options: [
{
text: 'C#',
ariaLabel: 'C Sharp',
},
{
text: 'Java',
},
],
};

const page = await newSpecPage({
components: [PickerColumnCmp],
template: () => <ion-picker-column col={col}></ion-picker-column>,
});

const firstOption = page.body.querySelector('ion-picker-column .picker-opt:nth-child(1)');
const secondOption = page.body.querySelector('ion-picker-column .picker-opt:nth-child(2)');

expect(firstOption.getAttribute('aria-label')).toBe('C Sharp');
expect(secondOption.getAttribute('aria-label')).toBe(null);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { h } from '@stencil/core';
import { newSpecPage } from '@stencil/core/testing';

import { PickerColumnCmp } from '../picker-column';

describe('picker-column', () => {
Expand Down
4 changes: 4 additions & 0 deletions core/src/components/picker/picker-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ export interface PickerColumnOption {
duration?: number;
transform?: string;
selected?: boolean;
/**
* The optional text to assign as the aria-label on the picker column option.
*/
ariaLabel?: string;
}