chore(FilterBar): Filter bar accessibility (#30812)

This commit is contained in:
alexandrusoare 2024-11-07 13:08:32 +02:00 committed by GitHub
parent de8282cea0
commit 5b2f005e80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 29 additions and 7 deletions

View File

@ -608,8 +608,9 @@ const Select = forwardRef(
<StyledHeader headerPosition={headerPosition}>{header}</StyledHeader>
)}
<StyledSelect
id={name}
allowClear={!isLoading && allowClear}
aria-label={ariaLabel || name}
aria-label={ariaLabel}
autoClearSearchValue={autoClearSearchValue}
dropdownRender={dropdownRender}
filterOption={handleFilterOption}

View File

@ -253,7 +253,10 @@ const FilterControl = ({
const label = useMemo(
() => (
<FilterControlTitleBox>
<FilterControlTitle data-test="filter-control-name">
<FilterControlTitle
id={`filter-name-${filter.id}`}
data-test="filter-control-name"
>
{name}
</FilterControlTitle>
{isRequired && <RequiredFieldIndicator />}
@ -315,7 +318,7 @@ const FilterControl = ({
<div>
<FormItem
label={label}
aria-label={name}
htmlFor={filter.id}
required={filter?.controlValues?.enableEmptyFilter}
validateStatus={validateStatus}
>

View File

@ -152,6 +152,7 @@ const getTooltipTitle = (
export default function DateFilterLabel(props: DateFilterControlProps) {
const {
name,
onChange,
onOpenPopover = noOp,
onClosePopover = noOp,
@ -384,6 +385,9 @@ export default function DateFilterLabel(props: DateFilterControlProps) {
getPopupContainer={trigger => trigger.parentElement as HTMLElement}
>
<DateLabel
name={name}
aria-labelledby={`filter-name-${props.name}`}
aria-describedby={`date-label-${props.name}`}
label={actualTimeRange}
isActive={show}
isPlaceholder={actualTimeRange === NO_TIME_RANGE}
@ -402,6 +406,9 @@ export default function DateFilterLabel(props: DateFilterControlProps) {
getPopupContainer={trigger => trigger.parentElement as HTMLElement}
>
<DateLabel
name={name}
aria-labelledby={`filter-name-${props.name}`}
aria-describedby={`date-label-${props.name}`}
onClick={toggleOverlay}
label={actualTimeRange}
isActive={show}

View File

@ -23,6 +23,7 @@ import { css, styled, useTheme, t } from '@superset-ui/core';
import Icons from 'src/components/Icons';
export type DateLabelProps = {
name?: string;
label: ReactNode;
isActive?: boolean;
isPlaceholder?: boolean;
@ -87,8 +88,12 @@ export const DateLabel = forwardRef(
(props: DateLabelProps, ref: RefObject<HTMLSpanElement>) => {
const theme = useTheme();
return (
<LabelContainer {...props} tabIndex={0}>
<span className="date-label-content" ref={ref}>
<LabelContainer {...props} tabIndex={0} role="button">
<span
id={`date-label-${props.name}`}
className="date-label-content"
ref={ref}
>
{typeof props.label === 'string' ? t(props.label) : props.label}
</span>
<Icons.CalendarOutlined

View File

@ -315,7 +315,10 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {
{Number.isNaN(Number(min)) || Number.isNaN(Number(max)) ? (
<h4>{t('Chosen non-numeric column')}</h4>
) : (
<StyledFormItem extra={formItemExtra}>
<StyledFormItem
aria-labelledby={`filter-name-${formData.nativeFilterId}`}
extra={formItemExtra}
>
<Wrapper
tabIndex={-1}
ref={inputRef}

View File

@ -293,6 +293,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
extra={formItemExtra}
>
<Select
name={formData.nativeFilterId}
allowClear
allowNewOptions={!searchAllOptions}
allowSelectAll={!searchAllOptions}

View File

@ -94,7 +94,7 @@ export default function TimeFilterPlugin(props: PluginFilterTimeProps) {
>
<DateFilterControl
value={filterState.value || NO_TIME_RANGE}
name="time_range"
name={props.formData.nativeFilterId || 'time_range'}
onChange={handleTimeRangeChange}
onOpenPopover={() => setFilterActive(true)}
onClosePopover={() => {

View File

@ -111,6 +111,7 @@ export default function PluginFilterTimeColumn(
{...formItemData}
>
<Select
name={formData.nativeFilterId}
allowClear
value={value}
placeholder={placeholderText}

View File

@ -121,6 +121,7 @@ export default function PluginFilterTimegrain(
{...formItemData}
>
<Select
name={formData.nativeFilterId}
allowClear
value={value}
placeholder={placeholderText}