From b8284e5d8d3b4cdc26555d44be2fcf90096e2ca1 Mon Sep 17 00:00:00 2001 From: Rage Lopez Date: Thu, 11 Jun 2026 09:09:49 -0500 Subject: [PATCH] Fix no-field message on All tab --- src/form/Form/NoFieldFound.test.tsx | 17 +++++++++++++++ src/form/Form/NoFieldFound.tsx | 34 +++++++++++++++++++---------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/form/Form/NoFieldFound.test.tsx b/src/form/Form/NoFieldFound.test.tsx index 4974ea1..f5ddd93 100644 --- a/src/form/Form/NoFieldFound.test.tsx +++ b/src/form/Form/NoFieldFound.test.tsx @@ -19,6 +19,23 @@ describe('NoFieldFound Component', () => { expect(screen.getByText('No Required fields found')).toBeInTheDocument(); }); + it('should not suggest switching tabs when the All tab is already selected', () => { + const mockContextValue: CanvasFormTabsContextResult = { + selectedTab: 'All', + setSelectedTab: jest.fn(), + }; + + render( + + + , + ); + + expect(screen.getByText('No fields found')).toBeInTheDocument(); + expect(screen.getByText('No field found matching this criteria.')).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: /All/i })).not.toBeInTheDocument(); + }); + it('should call onTabChange when the button is clicked', () => { const mockContextValue: CanvasFormTabsContextResult = { selectedTab: 'Required', diff --git a/src/form/Form/NoFieldFound.tsx b/src/form/Form/NoFieldFound.tsx index bb04512..7934dff 100644 --- a/src/form/Form/NoFieldFound.tsx +++ b/src/form/Form/NoFieldFound.tsx @@ -4,22 +4,32 @@ import { CanvasFormTabsContext } from '../providers/canvas-form-tabs.provider'; export const NoFieldFound: FunctionComponent<{ className?: string }> = (props) => { const canvasFormTabsContext = useContext(CanvasFormTabsContext); + const isAllTabSelected = canvasFormTabsContext.selectedTab === 'All'; return ( - - No field found matching this criteria. Please switch to the{' '} - {' '} - tab. + + No field found matching this criteria. + {!isAllTabSelected && ( + <> + {' '} + Please switch to the{' '} + {' '} + tab. + + )}