Skip to content
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

DataViews: Fix focus loss when removing all filters or resetting #67003

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
feedback
  • Loading branch information
ntsekouras committed Nov 14, 2024
commit 8351ad9f43f41d8b472f808d075235a2d4fe5628
23 changes: 16 additions & 7 deletions packages/dataviews/src/components/dataviews-filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ export function FiltersToggle( {
trigger={ buttonComponent }
/>
) : (
<FilterVisibilityToggle buttonRef={ buttonRef }>
<FilterVisibilityToggle
buttonRef={ buttonRef }
filtersCount={ view.filters?.length }
>
{ buttonComponent }
{ hasVisibleFilters && !! view.filters?.length && (
<span className="dataviews-filters-toggle__count">
{ view.filters?.length }
</span>
) }
</FilterVisibilityToggle>
) }
</div>
Expand All @@ -154,9 +152,11 @@ export function FiltersToggle( {

function FilterVisibilityToggle( {
buttonRef,
filtersCount,
children,
}: {
buttonRef: React.RefObject< HTMLButtonElement >;
filtersCount?: number;
children: React.ReactNode;
} ) {
// Focus the `add filter` button when unmounts.
Expand All @@ -166,7 +166,16 @@ function FilterVisibilityToggle( {
},
[ buttonRef ]
);
return children;
return (
<>
{ children }
{ !! filtersCount && (
<span className="dataviews-filters-toggle__count">
{ filtersCount }
</span>
) }
</>
);
}

function Filters() {
Expand Down
Loading