Select
@@ -278,14 +279,23 @@ export type SelectTreeProps = {
onChange: (e: { target: { value: NodeId | NodeId[] } }) => void;
sideControls?: ReactNode;
disabled?: boolean;
+ readOnly?: boolean;
// Controlled input value
inputValue?: string;
onChangeInputValue?: (value: string) => void;
};
+const OPEN_KEYS = ["Enter", " ", "ArrowDown", "ArrowUp"];
+
+const getSearchRegExp = (value: string) => {
+ const escapedValue = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+
+ return new RegExp(`^${escapedValue}|\\s${escapedValue}`, "i");
+};
+
const getFilteredOptions = (options: Tree, value: string) => {
- const rx = new RegExp(`^${value}|\\s${value}`, "i");
+ const rx = getSearchRegExp(value);
return value === ""
? options
@@ -411,6 +421,7 @@ export const SelectTree = ({
value,
onChange,
disabled,
+ readOnly,
sideControls,
onOpen,
onClose,
@@ -418,7 +429,12 @@ export const SelectTree = ({
id,
isMulti = false,
}: SelectTreeProps) => {
+ const generatedId = useId();
+ const triggerId = id ?? `select-tree-${generatedId}`;
+ const labelId = label ? `${triggerId}-label` : undefined;
+ const dialogId = `${triggerId}-dialog`;
const [openState, setOpenState] = useState(false);
+ const isOpen = open ?? openState;
const [minMenuWidth, setMinMenuWidth] = useState
();
const {
@@ -458,7 +474,30 @@ export const SelectTree = ({
return res;
}, [options, parentsRef]);
+ const nonSelectableValues = useMemo(() => {
+ return new Set(
+ flattenTree(options as HierarchyValue[])
+ .filter((node) => (node as TreeHierarchyValue).selectable === false)
+ .map((node) => node.value)
+ );
+ }, [options]);
+
+ const resultsCount = useMemo(() => {
+ const rx = getSearchRegExp(inputValue);
+
+ return flattenTree(filteredOptions as HierarchyValue[]).filter(
+ (node) => node.value !== FIELD_VALUE_NONE && rx.test(node.label)
+ ).length;
+ }, [filteredOptions, inputValue]);
+
const handleOpen = useEventCallback(() => {
+ if (disabled || readOnly) {
+ return;
+ }
+
+ inputRef.current
+ ?.querySelector(`[aria-haspopup="dialog"]`)
+ ?.focus();
setOpenState(true);
setMinMenuWidth(inputRef.current?.clientLeft);
onOpen?.();
@@ -472,11 +511,32 @@ export const SelectTree = ({
onClose?.();
});
- const handleNodeSelect = useEventCallback((_, v: NodeId | NodeId[]) => {
+ const handleNodeSelect = useEventCallback((_, v: NodeId) => {
+ if (nonSelectableValues.has(v)) {
+ return;
+ }
+
onChange({ target: { value: v } });
+ handleClose();
+ });
- if (!isMulti) {
- handleClose();
+ const handleMultiNodeSelect = useEventCallback((_, ids: NodeId[]) => {
+ const currentValues = value as NodeId[];
+ const addedIds = ids.filter((id) => !currentValues.includes(id));
+
+ if (addedIds.length === 1 && addedIds[0] === FIELD_VALUE_NONE) {
+ onChange({ target: { value: [] } });
+ return;
+ }
+
+ const nextValues = ids.filter(
+ (id) =>
+ id !== FIELD_VALUE_NONE &&
+ (currentValues.includes(id) || !nonSelectableValues.has(id))
+ );
+
+ if (!isEqual(nextValues, currentValues)) {
+ onChange({ target: { value: nextValues } });
}
});
@@ -564,12 +624,16 @@ export const SelectTree = ({
const paperProps = useMemo(
() => ({
+ id: dialogId,
+ role: "dialog",
+ "aria-modal": true,
+ "aria-labelledby": labelId,
sx: {
minWidth: minMenuWidth ?? 0,
boxShadow: 3,
},
}),
- [minMenuWidth]
+ [minMenuWidth, dialogId, labelId]
);
const menuTransitionProps = useMemo(
@@ -589,14 +653,12 @@ export const SelectTree = ({
);
const treeRef = useRef();
- const handleKeyDown: HTMLAttributes["onKeyDown"] = useEvent(
- (e) => {
- if (e.key === "Enter" || e.key == " ") {
- handleOpen();
- e.preventDefault();
- }
+ const handleKeyDown = useEvent((e: KeyboardEvent) => {
+ if (OPEN_KEYS.includes(e.key)) {
+ e.preventDefault();
+ handleOpen();
}
- );
+ });
useEffect(() => {
const inputNode = inputRef.current;
@@ -609,7 +671,7 @@ export const SelectTree = ({
{label && (
);
diff --git a/app/configurator/components/chart-configurator.tsx b/app/configurator/components/chart-configurator.tsx
index 285da6d2e..5d24d6a78 100644
--- a/app/configurator/components/chart-configurator.tsx
+++ b/app/configurator/components/chart-configurator.tsx
@@ -77,6 +77,7 @@ import {
OnOffControlTabField,
} from "@/configurator/components/field";
import { canRenderDatePickerField } from "@/configurator/components/field-date-picker";
+import { useFocusFilter } from "@/configurator/components/use-focus-filter";
import {
getFiltersByMappingStatus,
isConfiguring,
@@ -114,7 +115,7 @@ export const DataFilterSelectGeneric = ({
rawDimension,
filterDimensionIds,
index,
- disabled,
+ readOnly,
onRemove,
sideControls,
disableLabel,
@@ -123,7 +124,7 @@ export const DataFilterSelectGeneric = ({
rawDimension: Dimension;
filterDimensionIds: string[];
index: number;
- disabled?: boolean;
+ readOnly?: boolean;
onRemove?: () => void;
sideControls?: ReactNode;
disableLabel?: boolean;
@@ -179,10 +180,13 @@ export const DataFilterSelectGeneric = ({
marginRight: sideControls && dimension.isKeyDimension ? 7 : 0,
}}
>
-
+
{dimension.isKeyDimension ? null : (
((theme) => ({
},
}));
-const InteractiveDataFilterToggle = ({ id }: { id: string }) => {
+const InteractiveDataFilterToggle = ({
+ id,
+ filterLabel,
+}: {
+ id: string;
+ filterLabel: string;
+}) => {
const { checked, onChange } = useInteractiveDataFilterToggle(id);
return (
@@ -617,6 +627,10 @@ const InteractiveDataFilterToggle = ({ id }: { id: string }) => {
id: "controls.filters.interactive.toggle",
message: "Interactive",
})}
+ aria-label={t({
+ id: "controls.filters.interactive.toggle-for",
+ message: `Interactive: ${filterLabel}`,
+ })}
checked={checked}
onChange={onChange}
/>
@@ -668,6 +682,7 @@ export const ChartConfigurator = ({
const components = useMemo(() => {
return [...(dimensions ?? []), ...(measures ?? [])];
}, [dimensions, measures]);
+ const focusFilter = useFocusFilter();
if (components.length === 0) {
return (
@@ -800,7 +815,6 @@ export const ChartConfigurator = ({
d.id)}
index={i}
- disabled={fetching}
+ readOnly={fetching}
onRemove={() =>
handleRemoveDimensionFilter(dim)
}
- sideControls={}
+ sideControls={
+
+ }
/>
)}
@@ -828,7 +849,10 @@ export const ChartConfigurator = ({
{cubeAddableDims && cubeAddableDims.length > 0 ? (
-
+ focusFilter(dim.id)}
+ />
) : null}
) : null;
@@ -853,7 +877,13 @@ export const ChartConfigurator = ({
);
};
-const AddFilterButton = ({ dims }: { dims: Dimension[] }) => {
+const AddFilterButton = ({
+ dims,
+ onAdd,
+}: {
+ dims: Dimension[];
+ onAdd: (dimension: Dimension) => void;
+}) => {
const ref = useRef(null);
const {
isOpen: isMenuOpen,
@@ -878,7 +908,13 @@ const AddFilterButton = ({ dims }: { dims: Dimension[] }) => {
}
+ aria-label={t({
+ id: "controls.filters.interactive.toggle-calculation",
+ message: "Interactive chart mode",
+ })}
field={null}
path="interactiveFiltersConfig.calculation.active"
disabled={disabled}
diff --git a/app/configurator/components/custom-layers-selector.tsx b/app/configurator/components/custom-layers-selector.tsx
index 34059f362..250c7fffc 100644
--- a/app/configurator/components/custom-layers-selector.tsx
+++ b/app/configurator/components/custom-layers-selector.tsx
@@ -293,7 +293,6 @@ const DraggableLayer = ({
{(provided) => (