Skip to content

chore: put default fallback value for a11y #1731

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useOnResetValueEvent, useOnSetValueEvent } from "@mendix/widget-plugin-external-events/hooks";
import {
useOnResetValueEvent,
useOnSetValueEvent,
useAccessibilityValues
} from "@mendix/widget-plugin-external-events/hooks";
import { StringFilterController } from "@mendix/widget-plugin-filtering/controllers/input/StringInputController";
import { FilterFnList, InputWithFilters } from "@mendix/widget-plugin-filtering/controls";
import { useBasicSync } from "@mendix/widget-plugin-filtering/helpers/useBasicSync";
Expand Down Expand Up @@ -59,6 +63,11 @@ export const TextFilterContainer: (props: ContainerProps) => React.ReactElement
listener: controller.handleResetValue
});

const { screenReaderInputCaption } = useAccessibilityValues({
inputRef: controller.inputRef,
defaultValue: props.screenReaderInputCaption?.value
});

useOnSetValueEvent({ widgetName: props.name, listener: controller.handleSetValue });

return (
Expand All @@ -75,7 +84,7 @@ export const TextFilterContainer: (props: ContainerProps) => React.ReactElement
onFilterChange={controller.handleFilterFnChange}
placeholder={props.placeholder?.value}
screenReaderButtonCaption={props.screenReaderButtonCaption?.value}
screenReaderInputCaption={props.screenReaderInputCaption?.value}
screenReaderInputCaption={screenReaderInputCaption}
styles={props.style}
tabIndex={props.tabIndex}
defaultValue={props.defaultValue?.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { useOnResetValueEvent } from "./hooks/useOnResetValueEvent";
export { useOnSetValueEvent } from "./hooks/useOnSetValueEvent";
export { useOnResetFiltersEvent } from "./hooks/useOnResetFiltersEvent";
export { useListenChannelEvents } from "./hooks/useListenChannelEvents";
export { useAccessibilityValues } from "./hooks/useAccessibilityValues";
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useMemo } from "react";

type Params = {
inputRef: React.RefObject<HTMLInputElement>;
defaultValue: string | undefined;
};

export function useAccessibilityValues({ inputRef, defaultValue }: Params): {
screenReaderInputCaption: string;
} {
const screenReaderInputCaption = useMemo(() => {
if (defaultValue && defaultValue.length > 0) {
return defaultValue;
}
if (inputRef.current) {
const headerColumnNode = inputRef.current?.closest("[role='columnheader']");
if (headerColumnNode) {
const headerColumnTitle = headerColumnNode.getAttribute("title");
if (headerColumnTitle) {
return `Search ${headerColumnTitle}`;
}
}
}
return "";
}, [defaultValue, inputRef, inputRef.current]);

Check warning on line 25 in packages/shared/widget-plugin-external-events/src/hooks/useAccessibilityValues.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

React Hook useMemo has an unnecessary dependency: 'inputRef.current'. Either exclude it or remove the dependency array. Mutable values like 'inputRef.current' aren't valid dependencies because mutating them doesn't re-render the component

return {
screenReaderInputCaption
};
}
Loading