Skip to content

Commit

Permalink
Pass in input name for Input id in storybook (#638)
Browse files Browse the repository at this point in the history
* Pass in input name for input id

* version patch update
  • Loading branch information
jhp0621 authored Mar 26, 2024
1 parent d9e76f7 commit 052921a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@launchpadlab/lp-components",
"version": "10.0.0",
"version": "10.0.1",
"engines": {
"node": "^18.12 || ^20.0"
},
Expand Down
23 changes: 12 additions & 11 deletions stories/forms/labels/labeled-field.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ import { action } from '@storybook/addon-actions'

const StaticInput = (props) => <input {...props} />
const Input = dynamicInput()(StaticInput)
const inputName = 'inputName'

storiesOf('LabeledField', module)
.add('default', () => (
<LabeledField
{...{
input: {
name: 'input name',
name: inputName,
},
meta: {},
}}
>
<Input />
<Input id={inputName} />
</LabeledField>
))
.add('with error', () => (
<LabeledField
{...{
input: {
name: 'input name',
name: inputName,
},
meta: {
touched: true,
Expand All @@ -33,14 +34,14 @@ storiesOf('LabeledField', module)
},
}}
>
<Input />
<Input id={inputName} />
</LabeledField>
))
.add('hide error', () => (
<LabeledField
{...{
input: {
name: 'input name',
name: inputName,
},
meta: {
touched: true,
Expand All @@ -50,28 +51,28 @@ storiesOf('LabeledField', module)
hideErrorLabel: true,
}}
>
<Input />
<Input id={inputName} />
</LabeledField>
))
.add('with custom label', () => {
// eslint-disable-next-line
const CustomLabel = ({ onClickLabel }) => (
<label onClick={onClickLabel} htmlFor="inputName">
<label onClick={onClickLabel} htmlFor={inputName}>
This is a <b>custom</b> label
</label>
)
return (
<LabeledField
{...{
input: {
name: 'inputName',
name: inputName,
},
meta: {},
labelComponent: CustomLabel,
onClickLabel: action('Custom Label Clicked'),
}}
>
<Input id="inputName" />
<Input id={inputName} />
</LabeledField>
)
})
Expand All @@ -86,7 +87,7 @@ storiesOf('LabeledField', module)
<LabeledField
{...{
input: {
name: 'inputName',
name: inputName,
},
meta: {
touched: true,
Expand All @@ -96,7 +97,7 @@ storiesOf('LabeledField', module)
errorComponent: CustomError,
}}
>
<Input id="inputName" aria-describedby="inputError" />
<Input id={inputName} aria-describedby="inputError" />
</LabeledField>
)
})

0 comments on commit 052921a

Please sign in to comment.