Skip to content

Commit 99fd1c9

Browse files
committed
feat: scroll up on search and empty state handling
- Added a new CSS class for empty feature cells to improve styling. - Updated the FeaturesTable component to display a message when no features match the search query, enhancing user experience. - Introduced a ref for the dialog content to enable scrolling to the top when a search is performed.
1 parent d3dc674 commit 99fd1c9

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

packages/browser-sdk/src/toolbar/Features.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
}
6464
}
6565

66+
.feature-empty-cell {
67+
width: 100%;
68+
color: var(--gray500);
69+
padding: 6px 0;
70+
}
71+
6672
.feature-name-cell {
6773
white-space: nowrap;
6874
overflow: hidden;

packages/browser-sdk/src/toolbar/Features.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@ export function FeaturesTable({
1919
isOpen: boolean;
2020
setIsEnabledOverride: (key: string, isEnabled: boolean | null) => void;
2121
}) {
22+
const hasFeatures = features.length > 0;
23+
const hasShownFeatures = features.some((feature) =>
24+
feature.key
25+
.toLocaleLowerCase()
26+
.includes(searchQuery?.toLocaleLowerCase() ?? ""),
27+
);
28+
// List features that match the search query first
2229
const searchedFeatures =
2330
searchQuery === null
2431
? features
2532
: [...features].sort((a, _b) => (a.key.includes(searchQuery) ? -1 : 1));
26-
27-
if (searchedFeatures.length === 0) {
28-
return <div style={{ color: "var(--gray500)" }}>No features found</div>;
29-
}
3033
return (
3134
<table class="features-table" style={{ "--n": searchedFeatures.length }}>
3235
<tbody>
36+
{(!hasFeatures || !hasShownFeatures) && (
37+
<tr>
38+
<td class="feature-empty-cell" colSpan={3}>
39+
No features{" "}
40+
{!hasShownFeatures ? `matching "${searchQuery} "` : ""}
41+
found
42+
</td>
43+
</tr>
44+
)}
3345
{searchedFeatures.map((feature, index) => (
3446
<FeatureRow
3547
key={feature.key}

packages/browser-sdk/src/toolbar/Toolbar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default function Toolbar({
3737
position: ToolbarPosition;
3838
}) {
3939
const toggleToolbarRef = useRef<HTMLDivElement>(null);
40+
const dialogContentRef = useRef<HTMLDivElement>(null);
4041
const [features, setFeatures] = useState<Feature[]>([]);
4142

4243
const updateFeatures = useCallback(() => {
@@ -67,6 +68,7 @@ export default function Toolbar({
6768
const [search, setSearch] = useState<string | null>(null);
6869
const onSearch = (val: string) => {
6970
setSearch(val === "" ? null : val);
71+
dialogContentRef.current?.scrollTo({ top: 0 });
7072
};
7173

7274
const sortedFeatures = [...features].sort((a, b) =>
@@ -102,7 +104,7 @@ export default function Toolbar({
102104
<DialogHeader>
103105
<FeatureSearch onSearch={onSearch} />
104106
</DialogHeader>
105-
<DialogContent>
107+
<DialogContent innerRef={dialogContentRef}>
106108
<FeaturesTable
107109
appBaseUrl={appBaseUrl}
108110
features={sortedFeatures}

packages/browser-sdk/src/ui/Dialog.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,28 @@ function DialogArrow({
257257

258258
export function DialogHeader({
259259
children,
260+
innerRef,
260261
}: {
261262
children: preact.ComponentChildren;
263+
innerRef?: Ref<HTMLElement>;
262264
}) {
263-
return <header class="dialog-header">{children}</header>;
265+
return (
266+
<header ref={innerRef} class="dialog-header">
267+
{children}
268+
</header>
269+
);
264270
}
265271

266272
export function DialogContent({
267273
children,
274+
innerRef,
268275
}: {
269276
children: preact.ComponentChildren;
277+
innerRef?: Ref<HTMLDivElement>;
270278
}) {
271-
return <div class="dialog-content">{children}</div>;
279+
return (
280+
<div ref={innerRef} class="dialog-content">
281+
{children}
282+
</div>
283+
);
272284
}

0 commit comments

Comments
 (0)