Skip to content
Open
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,4 @@
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import DataViewTextFilter, { DataViewTextFilterProps } from './DataViewTextFilter';
import DataViewToolbar from '../DataViewToolbar';
Expand All @@ -22,6 +22,16 @@ describe('DataViewTextFilter component', () => {
expect(container).toMatchSnapshot();
});

it('should use chipTitle for the filter chip category when provided', () => {
render(<DataViewToolbar
filters={
<DataViewTextFilter {...defaultProps} chipTitle="Short name" />
}
/>);
expect(screen.getByText('Short name')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Filter by Test Filter')).toBeInTheDocument();
});

it('should focus the search input when "/" key is pressed and filter is visible', () => {
render(<DataViewToolbar
filters={
Expand Down
9 changes: 7 additions & 2 deletions packages/module/src/DataViewTextFilter/DataViewTextFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface DataViewTextFilterProps extends SearchInputProps {
value?: string;
/** Filter title displayed in the toolbar */
title: string;
/** Label for the applied filter chip / category; defaults to title */
chipTitle?: string;
/** Callback for when the input value changes */
onChange?: (event: React.FormEvent<HTMLInputElement> | undefined, value: string) => void;
/** Controls visibility of the filter in the toolbar */
Expand All @@ -24,6 +26,7 @@ export interface DataViewTextFilterProps extends SearchInputProps {
export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
filterId,
title,
chipTitle,
value = '',
onChange,
onClear = () => onChange?.(undefined, ''),
Expand All @@ -33,6 +36,8 @@ export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
enableShortcut = true,
...props
}: DataViewTextFilterProps) => {
const categoryName = chipTitle ?? title;

useEffect(() => {
if (!enableShortcut) {
return;
Expand Down Expand Up @@ -68,9 +73,9 @@ export const DataViewTextFilter: FC<DataViewTextFilterProps> = ({
<ToolbarFilter
key={ouiaId}
data-ouia-component-id={ouiaId}
labels={value.length > 0 ? [ { key: title, node: value } ] : []}
labels={value.length > 0 ? [ { key: categoryName, node: value } ] : []}
deleteLabel={() => onChange?.(undefined, '')}
categoryName={title}
categoryName={categoryName}
showToolbarItem={showToolbarItem}
>
<SearchInput
Expand Down
Loading