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: Adding aria label to property filter token operator button #491

Merged
merged 10 commits into from
Dec 1, 2022
1 change: 1 addition & 0 deletions pages/property-filter/common-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const i18nStrings: PropertyFilterProps.I18nStrings = {
tokenLimitShowMore: 'Show more',
tokenLimitShowFewer: 'Show fewer',
clearFiltersText: 'Clear filters',
tokenOperatorAriaLabel: 'Boolean Operator',
removeTokenButtonAriaLabel: () => 'Remove token',
enteredTextLabel: (text: string) => `Use: "${text}"`,
};
Expand Down
3 changes: 3 additions & 0 deletions src/internal/components/filtering-token/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface FilteringTokenProps {
andText: string;
orText: string;
dismissAriaLabel?: string;
operatorAriaLabel?: string;
disabled?: boolean;

children: React.ReactNode;
Expand All @@ -33,6 +34,7 @@ export default function FilteringToken({
andText,
orText,
dismissAriaLabel,
operatorAriaLabel,
disabled,
children,
onChange,
Expand All @@ -52,6 +54,7 @@ export default function FilteringToken({
selectedOption={{ value: operation, label: operation === 'and' ? andText : orText }}
onChange={e => onChange(e.detail.selectedOption.value as FilteringTokenProps.Operation)}
disabled={disabled}
ariaLabel={operatorAriaLabel}
/>
)}
<div
Expand Down
1 change: 1 addition & 0 deletions src/property-filter/__tests__/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const i18nStrings = {
tokenLimitShowMore: 'Show more',
tokenLimitShowFewer: 'Show fewer',
clearFiltersText: 'Clear filters',
tokenOperatorAriaLabel: 'Boolean Operator',
removeTokenButtonAriaLabel: (token: Token) =>
'Remove token ' + token.propertyKey + ' ' + token.operator + ' ' + token.value,
enteredTextLabel: (text: string) => `Use: "${text}"`,
Expand Down
6 changes: 6 additions & 0 deletions src/property-filter/__tests__/property-filter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ describe('property filter parts', () => {
expect.objectContaining({ detail: expect.objectContaining({ operation: 'and' }) })
);
});

test('can be used to check aria-label attirbute on the filter token operator', () => {
const secondToken = wrapper.findTokens()![1];
const operator = secondToken.findTokenOperation()?.findDropdown();
expect(operator?.findAll('button')[0].getElement()).toHaveAttribute('aria-label', 'Boolean Operator');
});
});
describe('dismiss button', () => {
test('causes onChange to fire, removing the token', () => {
Expand Down
1 change: 1 addition & 0 deletions src/property-filter/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export namespace PropertyFilterProps {
tokenLimitShowMore?: string;
tokenLimitShowFewer?: string;
clearFiltersText: string;
tokenOperatorAriaLabel?: string;
removeTokenButtonAriaLabel: (token: PropertyFilterProps.Token) => string;
enteredTextLabel: AutosuggestProps.EnteredTextLabel;
}
Expand Down
1 change: 1 addition & 0 deletions src/property-filter/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const TokenButton = ({
andText={i18nStrings.operationAndText}
orText={i18nStrings.operationOrText}
dismissAriaLabel={i18nStrings.removeTokenButtonAriaLabel(token)}
operatorAriaLabel={i18nStrings.tokenOperatorAriaLabel}
onChange={setOperation}
onDismiss={removeToken}
disabled={disabled}
Expand Down
3 changes: 3 additions & 0 deletions src/select/parts/trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface TriggerProps extends FormFieldValidationControlProps {
isOpen?: boolean;
triggerVariant?: SelectProps.TriggerVariant;
inFilteringToken?: boolean;
ariaLabel?: string;
varghvi marked this conversation as resolved.
Show resolved Hide resolved
}

const Trigger = React.forwardRef(
Expand All @@ -37,6 +38,7 @@ const Trigger = React.forwardRef(
isOpen,
placeholder,
disabled,
ariaLabel,
}: TriggerProps,
ref: React.Ref<HTMLButtonElement>
) => {
Expand Down Expand Up @@ -73,6 +75,7 @@ const Trigger = React.forwardRef(
inFilteringToken={inFilteringToken}
ariaDescribedby={ariaDescribedby}
ariaLabelledby={joinStrings(ariaLabelledby, triggerContentId)}
ariaLabel={ariaLabel}
>
{triggerContent}
</ButtonTrigger>
Expand Down