Skip to content

Commit

Permalink
chore(FilterBar): Filter bar accessibility (apache#30812)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrusoare authored Nov 7, 2024
1 parent de8282c commit 5b2f005
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 />}
Expand Down Expand Up @@ -315,7 +318,7 @@ const FilterControl = ({
<div>
<FormItem
label={label}
aria-label={name}
htmlFor={filter.id}
required={filter?.controlValues?.enableEmptyFilter}
validateStatus={validateStatus}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const getTooltipTitle = (

export default function DateFilterLabel(props: DateFilterControlProps) {
const {
name,
onChange,
onOpenPopover = noOp,
onClosePopover = noOp,
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
extra={formItemExtra}
>
<Select
name={formData.nativeFilterId}
allowClear
allowNewOptions={!searchAllOptions}
allowSelectAll={!searchAllOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default function PluginFilterTimeColumn(
{...formItemData}
>
<Select
name={formData.nativeFilterId}
allowClear
value={value}
placeholder={placeholderText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default function PluginFilterTimegrain(
{...formItemData}
>
<Select
name={formData.nativeFilterId}
allowClear
value={value}
placeholder={placeholderText}
Expand Down

0 comments on commit 5b2f005

Please sign in to comment.