Skip to content

Commit a3ab7a8

Browse files
authored
feat: Modal UI/UX fixes and updates (#2780)
* feat: Modal UI/UX fixes and updates * fix: manually handle common HTML entities to prevent XSS
1 parent 9986cbf commit a3ab7a8

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

packages/docsearch-css/src/_variables.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* modal */
2424
--docsearch-modal-width: 800px;
2525
--docsearch-modal-height: 600px;
26+
--docsearch-modal-variable-height: 60dvh;
2627
--docsearch-modal-background: rgb(245, 246, 247);
2728
--docsearch-modal-shadow: rgba(0, 0, 0, 0.2) 0px 12px 28px 0px,
2829
rgba(0, 0, 0, 0.1) 0px 2px 4px 0px,

packages/docsearch-css/src/modal.css

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@
247247
/* Modal Dropdown */
248248

249249
.DocSearch-Dropdown {
250-
height: calc(
250+
height: var(--docsearch-modal-variable-height);
251+
max-height: calc(
251252
var(--docsearch-modal-height) - var(--docsearch-spacing) -
252253
var(--docsearch-footer-height)
253254
);
@@ -791,7 +792,7 @@ assistive tech users */
791792
display: flex;
792793
flex-direction: column;
793794
width: 100%;
794-
gap: 16px;
795+
gap: 1em;
795796
font-size: 0.8em;
796797
margin-bottom: 8px;
797798
background: var(--docsearch-hit-background);
@@ -802,8 +803,9 @@ assistive tech users */
802803
}
803804

804805
.DocSearch-AskAiScreen-Query {
805-
font-size: 1.5em;
806-
line-break: anywhere;
806+
font-size: 1.25em;
807+
line-break: loose;
808+
line-height: 1.4;
807809
font-weight: 600;
808810
margin: 0;
809811
}
@@ -994,7 +996,7 @@ assistive tech users */
994996
.DocSearch-Markdown-Content {
995997
color: var(--docsearch-text-color);
996998
line-height: 1.6;
997-
font-size: 1em;
999+
font-size: 0.9355em;
9981000
word-wrap: break-word;
9991001
}
10001002

@@ -1003,7 +1005,7 @@ assistive tech users */
10031005
}
10041006

10051007
.DocSearch-Markdown-Content p {
1006-
margin: 1.2em 0;
1008+
margin: 1em 0;
10071009
}
10081010

10091011
.DocSearch-Markdown-Content p:last-child {
@@ -1104,7 +1106,7 @@ assistive tech users */
11041106

11051107
.DocSearch-Markdown-Content li {
11061108
color: var(--docsearch-text-color);
1107-
margin: 0.5em 0;
1109+
margin: 0.8em 0;
11081110
padding-left: 0.3em;
11091111
line-height: 1.6;
11101112
}
@@ -1140,7 +1142,7 @@ assistive tech users */
11401142
.DocSearch-Markdown-Content hr {
11411143
border: none;
11421144
border-top: 1px solid var(--docsearch-subtle-color);
1143-
margin: 2em 0;
1145+
margin: 1em 0;
11441146
}
11451147

11461148
.DocSearch-Markdown-Content table {
@@ -1175,9 +1177,10 @@ assistive tech users */
11751177

11761178
.DocSearch-AskAiScreen-MessageContent-Tool {
11771179
display: flex;
1178-
align-items: baseline;
1180+
align-items: center;
11791181
width: 100%;
11801182
color: var(--docsearch-muted-color);
1183+
line-height: 1.2;
11811184
}
11821185

11831186
.DocSearch-AskAiScreen-MessageContent-Tool.Tool--Result {

packages/docsearch-react/src/DocSearchModal.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,12 @@ export function DocSearchModal({
506506

507507
const handleSelectAskAiQuestion = React.useCallback(
508508
(toggle: boolean, query: string) => {
509+
if (toggle && askAiState === 'new-conversation') {
510+
// We're starting a new conversation, clear out current messages
511+
setMessages([]);
512+
setAskAiState('initial');
513+
}
514+
509515
onAskAiToggle(toggle);
510516
setStoppedStream(false);
511517
sendMessage({
@@ -534,7 +540,7 @@ export function DocSearchModal({
534540
autocompleteRef.current.setQuery('');
535541
}
536542
},
537-
[onAskAiToggle, sendMessage],
543+
[onAskAiToggle, sendMessage, askAiState, setAskAiState, setMessages],
538544
);
539545

540546
// feedback handler
@@ -784,7 +790,6 @@ export function DocSearchModal({
784790
};
785791

786792
const handleNewConversation = (): void => {
787-
setMessages([]);
788793
setAskAiState('new-conversation');
789794
};
790795

packages/docsearch-react/src/Results.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ interface ResultsProps<TItem extends BaseItem>
2323
}
2424

2525
export function Results<TItem extends StoredDocSearchHit>(props: ResultsProps<TItem>): JSX.Element | null {
26+
// The collection title, decoded to handle encoded HTML entities
27+
const decodedTitle = React.useMemo(() => {
28+
return props.title
29+
.replace(/&amp;/g, '&')
30+
.replace(/&lt;/g, '<')
31+
.replace(/&gt;/g, '>')
32+
.replace(/&quot;/g, '"')
33+
.replace(/&#039;/g, "'");
34+
}, [props.title]);
35+
2636
if (!props.collection || props.collection.items.length === 0) {
2737
return null;
2838
}
@@ -40,7 +50,7 @@ export function Results<TItem extends StoredDocSearchHit>(props: ResultsProps<TI
4050
if (props.collection.source.sourceId === 'recentConversations') {
4151
return (
4252
<section className="DocSearch-Hits">
43-
<div className="DocSearch-Hit-source">{props.title}</div>
53+
<div className="DocSearch-Hit-source">{decodedTitle}</div>
4454
<ul {...props.getListProps({ source: props.collection.source })}>
4555
{props.collection.items.map((item, index) => {
4656
return <Result key={[props.title, item.objectID].join(':')} item={item} index={index} {...props} />;
@@ -52,7 +62,7 @@ export function Results<TItem extends StoredDocSearchHit>(props: ResultsProps<TI
5262

5363
return (
5464
<section className="DocSearch-Hits">
55-
<div className="DocSearch-Hit-source">{props.title}</div>
65+
<div className="DocSearch-Hit-source">{decodedTitle}</div>
5666

5767
<ul {...props.getListProps({ source: props.collection.source })}>
5868
{props.collection.items.map((item, index) => {

0 commit comments

Comments
 (0)