Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit 0ba0be6

Browse files
nickcoutsosleMaik
authored andcommitted
Avoid form submit for events meant to add chips (#102)
* Avoid form submit for events meant to add chips This is mainly necessary for forms that contain a single ChipInput and nothing else as the default behaviour for Enter is to submit the form: https://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2 * Move form example to specific story * add descriptive text to story
1 parent d3dcda3 commit 0ba0be6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/ChipInput.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class ChipInput extends React.Component {
147147
const handleKeyDown = this.autoComplete.handleKeyDown
148148
this.autoComplete.handleKeyDown = (event) => {
149149
if (this.props.newChipKeyCodes.indexOf(event.keyCode) >= 0) {
150+
event.preventDefault()
150151
this.handleAddChip(event.target.value)
151152
this.autoComplete.setState({ searchText: '' })
152153
this.autoComplete.forceUpdate()

stories/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,12 @@ storiesOf('ChipInput', module)
205205
addOnBlur
206206
/>
207207
))
208+
.add('in a form', () => themed(
209+
<form>
210+
<ChipInput
211+
onChange={action('onChange')}
212+
floatingLabelText="This is a single chip input inside a <code>form</code>. Note that pressing Enter in the chip input does not submit the form."
213+
fullWidth
214+
/>
215+
</form>
216+
))

0 commit comments

Comments
 (0)