@@ -14,6 +14,7 @@ import BasicDetailsSearch from "@/components/prescriptionSearch/BasicDetailsSear
1414
1515import { HERO_TEXT } from "@/constants/ui-strings/SearchForAPrescriptionStrings"
1616import { PRESCRIPTION_SEARCH_TABS } from "@/constants/ui-strings/SearchTabStrings"
17+ import "@/styles/searchforaprescription.scss"
1718
1819export default function SearchPrescriptionPage ( ) {
1920 const location = useLocation ( )
@@ -41,48 +42,49 @@ export default function SearchPrescriptionPage() {
4142 setActiveTab ( tabIndex )
4243 } , [ pathname ] )
4344
44- const handleTabClick = ( tabIndex : number ) => {
45- setActiveTab ( tabIndex )
46- navigate ( PRESCRIPTION_SEARCH_TABS [ tabIndex ] . link )
47-
48- // Focus on the search input after navigation
49- setTimeout ( ( ) => {
50- let inputId : string | null = null
45+ useEffect ( ( ) => {
46+ const handleKeyDown = ( event : KeyboardEvent ) => {
47+ // Only handle arrow keys when not focused on an input element
48+ const activeElement = document . activeElement
49+ const isInputFocused = activeElement && (
50+ activeElement . tagName === "INPUT" ||
51+ activeElement . tagName === "TEXTAREA" ||
52+ activeElement . tagName === "SELECT" ||
53+ activeElement . hasAttribute ( "contenteditable" )
54+ )
5155
52- switch ( tabIndex ) {
53- case 0 :
54- inputId = "presc-id-input"
55- break
56- case 1 :
57- inputId = "nhs-number-input"
58- break
59- case 2 : {
60- // Remove focus from the tab after navigation for basic details
61- const activeElement = document . activeElement as HTMLElement
62- if ( activeElement && activeElement . blur ) {
63- activeElement . blur ( )
64- }
65- break
66- }
67- default :
68- break
56+ if ( isInputFocused ) {
57+ return
6958 }
7059
71- if ( inputId ) {
72- const inputElement = document . getElementById ( inputId ) as HTMLInputElement
73- if ( inputElement ) {
74- inputElement . focus ( )
75- }
60+ if ( event . key === "ArrowLeft" ) {
61+ event . preventDefault ( )
62+ const newIndex = activeTab > 0 ? activeTab - 1 : PRESCRIPTION_SEARCH_TABS . length - 1
63+ handleTabClick ( newIndex )
64+ } else if ( event . key === "ArrowRight" ) {
65+ event . preventDefault ( )
66+ const newIndex = activeTab < PRESCRIPTION_SEARCH_TABS . length - 1 ? activeTab + 1 : 0
67+ handleTabClick ( newIndex )
7668 }
77- } , 100 )
69+ }
70+
71+ document . addEventListener ( "keydown" , handleKeyDown )
72+ return ( ) => {
73+ document . removeEventListener ( "keydown" , handleKeyDown )
74+ }
75+ } , [ activeTab ] )
76+
77+ const handleTabClick = ( tabIndex : number ) => {
78+ setActiveTab ( tabIndex )
79+ navigate ( PRESCRIPTION_SEARCH_TABS [ tabIndex ] . link )
7880 }
7981
8082 // Default to prescription ID search if path not found
8183 const content = pathContent [ pathname ] || < PrescriptionIdSearch />
8284
8385 return (
8486 < Fragment >
85- < title > Search for a prescription </ title >
87+ < title > { HERO_TEXT } </ title >
8688 < main id = "search-for-a-prescription" data-testid = "search-for-a-prescription" >
8789 < Container className = "hero-container" data-testid = "search-hero-container" >
8890 < Row >
@@ -112,22 +114,12 @@ export default function SearchPrescriptionPage() {
112114 </ Col >
113115 </ Row >
114116 </ Container >
115- < div style = { {
116- width : "100vw" ,
117- marginLeft : "calc(-50vw + 50%)" ,
118- borderBottom : "1px solid #d8dde0" ,
119- height : "1px" ,
120- backgroundColor : "white"
121- } } > </ div >
122- < div style = { {
123- width : "100vw" ,
124- marginLeft : "calc(-50vw + 50%)" ,
125- backgroundColor : "#F0F4F5"
126- } } >
117+ < div className = "tab-divider" > </ div >
118+ < div className = "content-wrapper" >
127119 < Container >
128120 < Row >
129121 < Col width = "full" >
130- < div style = { { padding : "2rem" } } >
122+ < div className = "content- padding" >
131123 { content }
132124 </ div >
133125 </ Col >
0 commit comments