Skip to content

Commit 70998ab

Browse files
authored
Static header for accessible drawer content at page magnification (#2221)
* Chevron icon to close / slide up * Testing static header * Staic title and sticky slidedown opener. Rotating chevron * Remove CloseChevron * Reinstate opener background, repurpose darwer close button to close chat on first click * Update tests to reflect design change
1 parent e41d4e5 commit 70998ab

File tree

4 files changed

+53
-43
lines changed

4 files changed

+53
-43
lines changed

frontends/main/src/page-components/LearningResourceExpanded/AiChatSyllabusSlideDown.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ const SlideDown = styled.div<{
3434
}))
3535

3636
const Opener = styled.div(({ theme }) => ({
37+
position: "relative",
3738
":after": {
3839
content: "''",
3940
width: "100%",
4041
height: "50%",
4142
background: theme.custom.colors.white,
4243
display: "block",
4344
position: "absolute",
44-
top: 0,
45+
top: "-24px",
4546
borderBottom: `1px solid ${theme.custom.colors.lightGray2}`,
4647
zIndex: 1,
48+
paddingTop: "24px",
4749
},
4850
}))
4951

@@ -89,7 +91,7 @@ const StyledAiChat = styled(AiChat)<{
8991
topPosition: number
9092
}>(({ topPosition }) => ({
9193
".MitAiChat--root": {
92-
minHeight: `calc(100vh - ${topPosition + 43}px)`,
94+
minHeight: `calc(100vh - ${topPosition}px)`,
9395
},
9496
".MitAiChat--entryScreenContainer": {
9597
top: topPosition,

frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.test.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,7 @@ describe.each([true, false])(
393393
resource: course1,
394394
chatExpanded: true,
395395
})
396-
await user.click(
397-
screen.getByRole("button", { name: "Ask TIM about this course" }),
398-
)
396+
await user.click(screen.getByRole("button", { name: "Close" }))
399397

400398
const dataTestId = "ai-chat-entry-screen"
401399
expect(screen.getByTestId(dataTestId)).toBeInTheDocument()
@@ -407,27 +405,36 @@ describe.each([true, false])(
407405
})
408406
})
409407

410-
test.each([
411-
{ chatExpanded: false, expectChat: false },
412-
{ chatExpanded: true, expectChat: true },
413-
])(
414-
"When `chatExpanded=true`, chat button is pressed and interactive",
415-
({ chatExpanded, expectChat }) => {
416-
if (!enabled) return
417-
const resource = factories.learningResources.resource({
418-
resource_type: ResourceTypeEnum.Course,
419-
})
420-
setup({ resource, chatExpanded })
408+
test("When `chatExpanded=false`, chat button is not pressed and chat is inert", () => {
409+
if (!enabled) return
410+
const resource = factories.learningResources.resource({
411+
resource_type: ResourceTypeEnum.Course,
412+
})
413+
setup({ resource, chatExpanded: false })
421414

422-
screen.getByRole("button", {
423-
name: /Ask\sTIM/,
424-
pressed: chatExpanded,
425-
})
415+
screen.getByRole("button", {
416+
name: /Ask\sTIM/,
417+
pressed: false,
418+
})
426419

427-
// AiChat is always in the dom, but it's hidden and inert when not expanded.
428-
const aiChat = screen.getByTestId("ai-chat-entry-screen")
429-
expect(!!aiChat.closest("[inert]")).toBe(!expectChat)
430-
},
431-
)
420+
// AiChat is always in the dom, but it's hidden and inert when not expanded.
421+
const aiChat = screen.getByTestId("ai-chat-entry-screen")
422+
expect(!!aiChat.closest("[inert]")).toBe(true)
423+
})
424+
425+
test("When `chatExpanded=true`, chat is not inert until closed", async () => {
426+
if (!enabled) return
427+
const resource = factories.learningResources.resource({
428+
resource_type: ResourceTypeEnum.Course,
429+
})
430+
setup({ resource, chatExpanded: true })
431+
432+
const aiChat = screen.getByTestId("ai-chat-entry-screen")
433+
expect(!!aiChat.closest("[inert]")).toBe(false)
434+
435+
await user.click(screen.getByRole("button", { name: "Close" }))
436+
437+
expect(!!aiChat.closest("[inert]")).toBe(true)
438+
})
432439
},
433440
)

frontends/main/src/page-components/LearningResourceExpanded/LearningResourceExpanded.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ const ContentSection = styled.div<{
3737
position: "relative",
3838
}))
3939

40-
const StyledAiChatSyllabusOpener = styled(AiChatSyllabusOpener)<{
41-
top: number
42-
}>(({ top }) => ({
43-
position: "sticky",
44-
top,
45-
zIndex: 2,
46-
}))
47-
4840
const TopContainer = styled.div<{ chatEnabled: boolean }>(
4941
({ theme, chatEnabled }) => ({
5042
display: "flex",
@@ -238,15 +230,20 @@ const LearningResourceExpanded: React.FC<LearningResourceExpandedProps> = ({
238230
ref={titleSectionRef}
239231
titleId={titleId}
240232
resource={resource}
241-
onClickClose={closeDrawer}
233+
onClickClose={
234+
chatTransitionState === ChatTransitionState.Open
235+
? () => onChatOpenerToggle(false)
236+
: closeDrawer
237+
}
242238
/>
243239
{chatEnabled ? (
244240
<>
245-
<StyledAiChatSyllabusOpener
246-
open={chatExpanded}
247-
top={titleSectionHeight}
248-
onToggleOpen={onChatOpenerToggle}
249-
/>
241+
{chatTransitionState !== ChatTransitionState.Open ? (
242+
<AiChatSyllabusOpener
243+
open={chatExpanded}
244+
onToggleOpen={onChatOpenerToggle}
245+
/>
246+
) : null}
250247
<AiSyllabusBotSlideDown
251248
resource={resource}
252249
open={chatExpanded}

frontends/main/src/page-components/LearningResourceExpanded/TitleSection.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ import { RiCloseLargeLine } from "@remixicon/react"
88

99
const TitleContainer = styled.div({
1010
display: "flex",
11-
position: "sticky",
1211
justifyContent: "space-between",
1312
top: "0",
14-
padding: "24px 28px",
13+
padding: "24px 72px 24px 28px",
1514
gap: "16px",
16-
zIndex: 2,
15+
zIndex: 3,
1716
backgroundColor: theme.custom.colors.white,
1817
[theme.breakpoints.down("md")]: {
19-
padding: "24px 16px",
18+
padding: "24px 60px 24px 16px",
2019
},
2120
})
2221

2322
const CloseButton = styled(ActionButton)(({ theme }) => ({
23+
position: "fixed",
24+
right: "28px",
25+
[theme.breakpoints.down("md")]: {
26+
right: "16px",
27+
},
2428
"&&&": {
2529
flexShrink: 0,
2630
backgroundColor: theme.custom.colors.lightGray2,

0 commit comments

Comments
 (0)