Skip to content

Commit 03e1779

Browse files
authored
Merge pull request #85 from oramasearch/feature/orm-2241
Add on modal close event + use dialog tag instead of role
2 parents 2b7f24d + de64245 commit 03e1779

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

apps/demo-react/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const SearchBoxPage = () => {
9393
<div className="component-row">
9494
<OramaSearchButton colorScheme="system">Search</OramaSearchButton>
9595
<OramaSearchBox
96+
onModalClosed={() => {
97+
console.log('closed')
98+
}}
9699
colorScheme="system"
97100
index={{
98101
api_key: API_KEY,

packages/ui-stencil-vue/lib/components.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ export const OramaSearchBox = /*@__PURE__*/ defineContainer<JSX.OramaSearchBox>(
205205
'startConversation',
206206
'answerGenerated',
207207
'answerSourceClick',
208-
'chatMarkdownLinkClicked'
208+
'chatMarkdownLinkClicked',
209+
'modalClosed'
209210
]);
210211

211212

packages/ui-stencil/src/components.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ declare global {
558558
"answerGenerated": OnAnswerGeneratedCallbackProps;
559559
"answerSourceClick": OnAnswerSourceClickCallbackProps;
560560
"chatMarkdownLinkClicked": OnChatMarkdownLinkClickedCallbackProps;
561+
"modalClosed": any;
561562
}
562563
interface HTMLOramaSearchBoxElement extends Components.OramaSearchBox, HTMLStencilElement {
563564
addEventListener<K extends keyof HTMLOramaSearchBoxElementEventMap>(type: K, listener: (this: HTMLOramaSearchBoxElement, ev: OramaSearchBoxCustomEvent<HTMLOramaSearchBoxElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
@@ -901,6 +902,10 @@ declare namespace LocalJSX {
901902
* Fired when the chat is cleared
902903
*/
903904
"onClearChat"?: (event: OramaSearchBoxCustomEvent<void>) => void;
905+
/**
906+
* Fired when modal is closed
907+
*/
908+
"onModalClosed"?: (event: OramaSearchBoxCustomEvent<any>) => void;
904909
/**
905910
* Fired when search successfully resolves
906911
*/

packages/ui-stencil/src/components/internal/orama-modal/orama-modal.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ export class OramaModal {
136136
}
137137

138138
render() {
139-
if(!this.modalIsOpen) {
139+
if (!this.modalIsOpen) {
140140
return null
141141
}
142142

143143
return (
144-
<div
144+
<dialog
145145
class={`modal ${this.modalIsOpen ? 'open' : ''}`}
146-
role="dialog"
147146
aria-modal="true"
148147
aria-labelledby="modalTitle"
149148
aria-describedby="modalContent"
@@ -159,7 +158,7 @@ export class OramaModal {
159158
Close
160159
</button>
161160
</div>
162-
</div>
161+
</dialog>
163162
)
164163
}
165164
}

packages/ui-stencil/src/components/orama-search-box/orama-search-box.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ export class SearchBox {
197197
@Event({ bubbles: true, composed: true, cancelable: true })
198198
chatMarkdownLinkClicked: EventEmitter<OnChatMarkdownLinkClickedCallbackProps>
199199

200+
/**
201+
* Fired when modal is closed
202+
*/
203+
@Event({ bubbles: true, composed: true })
204+
modalClosed: EventEmitter
205+
200206
wrapperRef!: HTMLElement
201207

202208
schemaQuery: MediaQueryList
@@ -239,6 +245,8 @@ export class SearchBox {
239245
if (!event.detail.open) {
240246
this.globalStore.state.open = false
241247
this.open = false
248+
249+
this.modalClosed.emit()
242250
}
243251
}
244252
}

packages/ui-stencil/src/components/orama-search-box/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
| `answerSourceClick` | Fired when user clicks on answer source | `CustomEvent<{ source: SearchResult; }>` |
4242
| `chatMarkdownLinkClicked` | Fired when user clicks on chat markdown link | `CustomEvent<{ text: string; href: string; }>` |
4343
| `clearChat` | Fired when the chat is cleared | `CustomEvent<void>` |
44+
| `modalClosed` | Fired when modal is closed | `CustomEvent<any>` |
4445
| `searchCompleted` | Fired when search successfully resolves | `CustomEvent<{ clientSearchParams: ClientSearchParams; result: { results: SearchResultBySection[]; resultsCount: number; facets: Facet[]; }; }>` |
4546
| `searchResultClick` | Fired when user clicks on search result | `CustomEvent<{ result: SearchResult; }>` |
4647
| `startConversation` | Fired as soon as the conversation is started | `CustomEvent<{ userPrompt: string; systemPrompts: string[]; }>` |

0 commit comments

Comments
 (0)