Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 8f81ac5

Browse files
Add ability to pass form props to KeywordSearchWidget
1 parent c4ced22 commit 8f81ac5

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.0.3-0] (beta) - 2023-13-02
9+
10+
## Added
11+
12+
- ability to pass form props to `KeywordSearchWidget`
13+
814
## [3.0.2-0] (beta) - 2023-13-02
915

1016
## Added

cypress/component/KeywordSearchWidget.cy.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ describe('<KeywordSearchWidget />', () => {
5050
<KeywordSearchWidget
5151
categories={categories}
5252
onKeywordSelection={cy.stub().as('onKeywordSelection')}
53+
formProps={{
54+
'aria-label': 'Filter by'
55+
}}
5356
/>
5457
</StyledTestWrapper>
5558
)
5659

60+
cy.findByLabelText('Filter by')
61+
5762
cy.findByText('Spatial coverage').click()
5863
cy.findByText(/Global/i).click()
5964
cy.findByText(/Europe/i)

src/widgets/KeywordSearchWidget.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export interface KeywordSearchWidgetProps {
2525
* A custom transformer for the query parameter. Defaults to using encodeURIComponent.
2626
*/
2727
keywordQueryParamTransformer?: (category: string, keyword: string) => string
28+
29+
/**
30+
* Optional intrinsic props for the wrapper form.
31+
*/
32+
formProps?: JSX.IntrinsicElements['form']
2833
}
2934

3035
type Selections = Record<string, string[]>
@@ -37,7 +42,8 @@ const KeywordSearchWidget = ({
3742
categories,
3843
onKeywordSelection,
3944
keywordQueryParam = 'kw',
40-
keywordQueryParamTransformer
45+
keywordQueryParamTransformer,
46+
formProps
4147
}: KeywordSearchWidgetProps) => {
4248
/**
4349
* Keep track of the selected keywords. This is used to preserve selections when accordions are closed and subsequently opened.
@@ -99,6 +105,7 @@ const KeywordSearchWidget = ({
99105
ev.stopPropagation()
100106
onKeywordSelection?.(getSelectedKeywordsAsQueryParams(selections))
101107
}}
108+
{...formProps}
102109
>
103110
{categories.map(cat => {
104111
const { category } = cat

0 commit comments

Comments
 (0)