Skip to content

Commit

Permalink
fix: Property filter empty state visible when no properties (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot authored Sep 27, 2023
1 parent abdd30c commit cf89e65
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function () {
countText={`${items.length} matches`}
i18nStrings={i18nStrings}
expandToViewport={true}
filteringEmpty="No properties"
/>
}
columnDefinitions={columnDefinitions.slice(0, 2)}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/components/autosuggest-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const AutosuggestInput = React.forwardRef(
/>
}
onMouseDown={handleDropdownMouseDown}
open={open && !!dropdownContent}
open={open && (!!dropdownContent || !!dropdownFooter)}
footer={
dropdownFooterRef && (
<div ref={dropdownFooterRef} className={styles['dropdown-footer']}>
Expand Down
33 changes: 29 additions & 4 deletions src/property-filter/__tests__/property-filter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const filteringOptions: readonly FilteringOption[] = [
];

const defaultProps: PropertyFilterProps = {
filteringEmpty: 'Empty',
filteringProperties,
filteringOptions,
filteringPlaceholder: 'Search',
Expand Down Expand Up @@ -1002,18 +1003,42 @@ describe('property filter parts', () => {
});

describe('dropdown states', () => {
it('when free text filtering is allowed and no property is matched dropdown is visible but aria-expanded is false', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({ disableFreeTextFiltering: false });
it('when free text filtering is allowed and no property is matched the dropdown is visible but aria-expanded is false', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({
disableFreeTextFiltering: false,
filteringProperties: [],
});
wrapper.setInputValue('free-text');
expect(wrapper.findNativeInput().getElement()).toHaveAttribute('aria-expanded', 'false');
expect(wrapper.findDropdown().findOpenDropdown()!.getElement()).toHaveTextContent('Use: "free-text"');
});
it('when free text filtering is not allowed and no property is matched dropdown is not shown and aria-expanded is false', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({ disableFreeTextFiltering: true });
it('when free text filtering is not allowed and no property is matched the dropdown is not shown and aria-expanded is false', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({
disableFreeTextFiltering: true,
filteringProperties: [],
});
wrapper.setInputValue('free-text');
expect(wrapper.findNativeInput().getElement()).toHaveAttribute('aria-expanded', 'false');
expect(wrapper.findDropdown().findOpenDropdown()).toBe(null);
});
it('when free text filtering is allowed and no properties available the filtering-empty is shown', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({
disableFreeTextFiltering: false,
filteringProperties: [],
});
wrapper.focus();
expect(wrapper.findNativeInput().getElement()).toHaveAttribute('aria-expanded', 'true');
expect(wrapper.findDropdown().findOpenDropdown()!.getElement()).toHaveTextContent('Empty');
});
it('when free text filtering is not allowed and no properties available the filtering-empty is shown', () => {
const { propertyFilterWrapper: wrapper } = renderComponent({
disableFreeTextFiltering: true,
filteringProperties: [],
});
wrapper.focus();
expect(wrapper.findNativeInput().getElement()).toHaveAttribute('aria-expanded', 'true');
expect(wrapper.findDropdown().findOpenDropdown()!.getElement()).toHaveTextContent('Empty');
});
});

describe('properties compatibility', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/property-filter/property-filter-autosuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const PropertyFilterAutosuggest = React.forwardRef(
dropdownContentKey={customForm ? 'custom' : 'options'}
dropdownContent={content}
dropdownFooter={
dropdownStatus.isSticky ? (
dropdownStatus.isSticky && dropdownStatus.content ? (
<DropdownFooter
content={dropdownStatus.content}
hasItems={autosuggestItemsState.items.length >= 1}
Expand Down

0 comments on commit cf89e65

Please sign in to comment.