Skip to content

Commit 7402038

Browse files
r0b1ngjulivan
authored andcommitted
chore: remove unused separator, it is done via css
also use clear button again
1 parent 8acf8a7 commit 7402038

5 files changed

Lines changed: 39 additions & 36 deletions

File tree

packages/pluggableWidgets/datagrid-dropdown-filter-web/src/__tests__/DatagridDropdownFilter.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EnumFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/EnumFilterStore";
22
import { FilterAPI } from "@mendix/widget-plugin-filtering/context";
33
import { ObservableFilterHost } from "@mendix/widget-plugin-filtering/typings/ObservableFilterHost";
4-
import { listAttribute } from "@mendix/widget-plugin-test-utils";
4+
import { listAttribute, dynamicValue } from "@mendix/widget-plugin-test-utils";
55
import "@testing-library/jest-dom";
66
import { render, waitFor } from "@testing-library/react";
77
import { AssociationMetaData, AttributeMetaData } from "mendix";
@@ -23,6 +23,7 @@ const commonProps: DatagridDropdownFilterContainerProps = {
2323
filterable: false,
2424
multiSelect: false,
2525
clearable: false,
26+
emptySelectionCaption: dynamicValue("Select"),
2627
selectedItemsStyle: "text",
2728
selectionMethod: "checkbox"
2829
};

packages/pluggableWidgets/datagrid-dropdown-filter-web/src/__tests__/__snapshots__/DatagridDropdownFilter.spec.tsx.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
exports[`Dropdown Filter with single instance with single attribute renders correctly 1`] = `
44
<DocumentFragment>
55
<div
6+
aria-activedescendant=""
7+
aria-controls="downshift-:r0:-menu"
8+
aria-expanded="false"
9+
aria-haspopup="listbox"
10+
aria-label="Select"
611
class="widget-dropdown-filter form-control variant-select filter-custom-class"
712
data-empty="true"
813
data-expanded="false"
14+
id="downshift-:r0:-toggle-button"
15+
role="combobox"
16+
tabindex="0"
917
>
10-
<button
11-
aria-activedescendant=""
12-
aria-controls="downshift-:r0:-menu"
13-
aria-expanded="false"
14-
aria-haspopup="listbox"
15-
aria-label="Select"
18+
<div
1619
class="widget-dropdown-filter-input-container"
17-
id="downshift-:r0:-toggle-button"
18-
role="combobox"
19-
tabindex="0"
2020
>
2121
<span
2222
class="widget-dropdown-filter-toggle"
@@ -37,7 +37,7 @@ exports[`Dropdown Filter with single instance with single attribute renders corr
3737
/>
3838
</svg>
3939
</div>
40-
</button>
40+
</div>
4141
<div
4242
class="widget-dropdown-filter-popover"
4343
hidden=""
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createElement, Fragment, ReactElement } from "react";
1+
import { createElement, ReactElement, useCallback } from "react";
22
import { Cross } from "../picker-primitives";
33

44
type ClearButtonClassNamesProps = {
@@ -10,18 +10,26 @@ type ClearButtonClassNamesProps = {
1010
type ClearButtonProps = {
1111
cls: ClearButtonClassNamesProps;
1212
onClick?: () => void;
13-
showSeparator?: boolean;
1413
visible: boolean;
1514
};
1615

1716
export function ClearButton(props: ClearButtonProps): ReactElement | null {
18-
const { cls, onClick, showSeparator, visible } = props;
17+
const { cls, onClick, visible } = props;
18+
19+
const onClickHandler = useCallback(
20+
(e: React.MouseEvent<HTMLButtonElement>) => {
21+
e.stopPropagation();
22+
e.preventDefault();
23+
if (onClick) {
24+
onClick();
25+
}
26+
},
27+
[onClick]
28+
);
29+
1930
return visible ? (
20-
<Fragment>
21-
<button className={cls.clear} tabIndex={-1} aria-label="Clear combobox" onClick={onClick}>
22-
<Cross className={cls.clearIcon} />
23-
</button>
24-
{showSeparator && <div className={cls.separator} role="presentation" />}
25-
</Fragment>
31+
<button className={cls.clear} aria-label="Clear selection" onClick={onClickHandler}>
32+
<Cross className={cls.clearIcon} />
33+
</button>
2634
) : null;
2735
}

packages/shared/widget-plugin-dropdown-filter/src/controls/combobox/Combobox.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export const Combobox = observer(function Combobox(props: ComboboxProps) {
5555
props.onClear();
5656
inputRef.current?.focus();
5757
}}
58-
showSeparator={false}
5958
visible={!props.empty}
6059
/>
6160
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>

packages/shared/widget-plugin-dropdown-filter/src/controls/select/Select.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { useSelect, UseSelectProps } from "downshift";
33
import { observer } from "mobx-react-lite";
44
import React, { createElement, useRef } from "react";
55
import { OptionWithState } from "../../typings/OptionWithState";
6+
import { ClearButton } from "../base/ClearButton";
67
import { OptionsWrapper } from "../base/OptionsWrapper";
78
import { useFloatingMenu } from "../hooks/useFloatingMenu";
8-
import { Arrow, classes, Cross } from "../picker-primitives";
9+
import { Arrow, classes } from "../picker-primitives";
910

1011
interface SelectProps {
1112
value: string;
@@ -51,20 +52,14 @@ export const Select = observer(function Select(props: SelectProps): React.ReactE
5152
>
5253
<span className={cls.toggle}>{props.value}</span>
5354
<div className={`${cls.root}-controls`}>
54-
{showClear && (
55-
<div
56-
className={cls.clear}
57-
tabIndex={-1}
58-
aria-label="Clear combobox"
59-
onClick={event => {
60-
event.stopPropagation();
61-
props.onClear();
62-
toggleRef.current?.focus();
63-
}}
64-
>
65-
<Cross />
66-
</div>
67-
)}
55+
<ClearButton
56+
cls={cls}
57+
onClick={() => {
58+
props.onClear();
59+
toggleRef.current?.focus();
60+
}}
61+
visible={showClear}
62+
/>
6863
<Arrow className={cls.stateIcon} />
6964
</div>
7065
</button>

0 commit comments

Comments
 (0)