Skip to content

Commit 0828d23

Browse files
some tidy up. extract code, extract css
1 parent 9cf8151 commit 0828d23

File tree

3 files changed

+59
-45
lines changed

3 files changed

+59
-45
lines changed

.github/workflows/run_regression_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
GITHUB-TOKEN: ${{ steps.generate-token.outputs.token }}
7474
run: |
7575
if [[ "$TARGET_ENVIRONMENT" != "prod" && "$TARGET_ENVIRONMENT" != "ref" ]]; then
76-
REGRESSION_TEST_REPO_TAG="v3.5.10" # This is the tag or branch of the regression test code to run, usually a version tag like v3.1.0 or a branch name
76+
REGRESSION_TEST_REPO_TAG="aea-5327-tabsets" # This is the tag or branch of the regression test code to run, usually a version tag like v3.1.0 or a branch name
7777
REGRESSION_TEST_WORKFLOW_TAG="v3.5.10" # This is the tag of the github workflow to run, usually the same as REGRESSION_TEST_REPO_TAG
7878
7979
if [[ -z "$REGRESSION_TEST_REPO_TAG" || -z "$REGRESSION_TEST_WORKFLOW_TAG" ]]; then

packages/cpt-ui/src/pages/SearchPrescriptionPage.tsx

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import BasicDetailsSearch from "@/components/prescriptionSearch/BasicDetailsSear
1414

1515
import {HERO_TEXT} from "@/constants/ui-strings/SearchForAPrescriptionStrings"
1616
import {PRESCRIPTION_SEARCH_TABS} from "@/constants/ui-strings/SearchTabStrings"
17+
import "@/styles/searchforaprescription.scss"
1718

1819
export 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>

packages/cpt-ui/src/styles/searchforaprescription.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,25 @@
2222
margin: 0 16px;
2323
max-width: 960px;
2424
}
25+
26+
.nhsuk-tab-set {
27+
text-decoration: underline;
28+
}
29+
30+
.tab-divider {
31+
width: 100vw;
32+
margin-left: calc(-50vw + 50%);
33+
border-bottom: 1px solid #d8dde0;
34+
height: 1px;
35+
background-color: white;
36+
}
37+
38+
.content-wrapper {
39+
width: 100vw;
40+
margin-left: calc(-50vw + 50%);
41+
background-color: #F0F4F5;
42+
}
43+
44+
.content-padding {
45+
padding: 2rem;
46+
}

0 commit comments

Comments
 (0)