Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-storefront",
"version": "8.0.1",
"version": "8.1.0",
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
"module": "./index.js",
"license": "Apache-2.0",
Expand Down
6 changes: 6 additions & 0 deletions src/search/SearchField.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const SearchField = forwardRef(
submitButtonVariant,
showClearButton,
SubmitButtonComponent,
SubmitButtonIcon,
clearButtonProps,
inputProps,
value,
Expand Down Expand Up @@ -167,6 +168,7 @@ const SearchField = forwardRef(
[classes.hidden]: empty,
})}
text={value}
ButtonIcon={SubmitButtonIcon}
{...submitButtonProps}
/>
)}
Expand All @@ -184,6 +186,10 @@ SearchField.propTypes = {
* The component to use for the submit button.
*/
SubmitButtonComponent: PropTypes.elementType,
/**
* An icon to use for the submit button.
*/
SubmitButtonIcon: PropTypes.elementType,
/**
* The type of submit button to display.
*/
Expand Down
14 changes: 10 additions & 4 deletions src/search/SearchSubmitButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SearchIcon from '@material-ui/icons/Search'
import React from 'react'
import makeStyles from '@material-ui/core/styles/makeStyles'
import PropTypes from 'prop-types'
import SearchIcon from '@material-ui/icons/Search'

export const styles = theme => ({
/**
Expand All @@ -20,7 +20,7 @@ const useStyles = makeStyles(styles, { name: 'RSFSearchSubmitButton' })
/**
* A button to submit the search. All other props are spread to the provided `Component`.
*/
export default function SearchSubmitButton({ Component, classes, text, ...others }) {
export default function SearchSubmitButton({ Component, ButtonIcon, classes, text, ...others }) {
classes = useStyles({ classes })

return (
Expand All @@ -32,7 +32,7 @@ export default function SearchSubmitButton({ Component, classes, text, ...others
disabled={text.trim().length === 0}
{...others}
>
<SearchIcon />
<ButtonIcon />
</Component>
)
}
Expand All @@ -46,10 +46,16 @@ SearchSubmitButton.propTypes = {
* A Material UI button component to display.
*/
Component: PropTypes.elementType.isRequired,
/**
* A Material UI button component to display.
*/
ButtonIcon: PropTypes.elementType,
/**
* The current search text.
*/
text: PropTypes.string.isRequired,
}

SearchSubmitButton.defaultProps = {}
SearchSubmitButton.defaultProps = {
ButtonIcon: SearchIcon,
}
1 change: 0 additions & 1 deletion test/search/SearchField.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from 'react'
import { mount } from 'enzyme'
import SearchField from 'react-storefront/search/SearchField'
import SearchContext from 'react-storefront/search/SearchContext'
import SearchSubmitButton from 'react-storefront/search/SearchSubmitButton'
import { Fab, Button } from '@material-ui/core'
import { IconButton } from '@material-ui/core'
Expand Down
6 changes: 6 additions & 0 deletions test/search/SearchSubmitButton.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Apps } from '@material-ui/icons'
import React from 'react'
import { mount } from 'enzyme'
import SearchSubmitButton from 'react-storefront/search/SearchSubmitButton'
Expand All @@ -24,4 +25,9 @@ describe('SearchSubmitButton', () => {
wrapper = mount(<SearchSubmitButton Component={Button} text="" spreadprops="spreadpropstest" />)
expect(wrapper.find(Button).prop('spreadprops')).toBe('spreadpropstest')
})

it('should change the icon based on the given prop', () => {
wrapper = mount(<SearchSubmitButton ButtonIcon={Apps} Component={Button} text="" />)
expect(wrapper.find(Apps)).toExist()
})
})