Skip to content

Commit

Permalink
fix: add className property to ListInput
Browse files Browse the repository at this point in the history
  • Loading branch information
jwertkin authored and jcestibariz committed Aug 7, 2024
1 parent dc3953d commit 806d9c9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/pelagos/__tests__/listInput/ListInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('ListInput', () => {
expect(wrapper.getElement()).toMatchSnapshot();
});

it('renders expected elements when className is set', () => {
const wrapper = shallow(
<ListInput id="test" className="TestClass" label="Test" list={[{id: '0', name: 'test'}]} />
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(useRandomId.mock.calls).toEqual([['test']]);
});

it('renders expected elements when error is set', () => {
const wrapper = shallow(
<ListInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,49 @@ exports[`ListInput rendering renders expected elements when the list is empty 1`
</div>
</div>
`;

exports[`ListInput rendering renders expected elements when className is set 1`] = `
<div
className="ListInput TestClass"
>
<div
aria-live="assertive"
className="sr-only"
/>
<LabelLine
error={false}
htmlFor="random-id"
id="random-id-label"
text="Test"
/>
<ComboBox
aria-describedby="random-id-helper"
autoSelect={true}
error={false}
getSuggestions={[Function]}
id="random-id"
onChange={[Function]}
onEnter={[Function]}
onTextChange={[Function]}
text=""
/>
<FieldHelper
id="random-id-helper"
/>
<ListEntries
className="ListInput__list"
highlightKey={null}
id="random-id-grid"
list={
[
{
"id": "0",
"name": "test",
},
]
}
onHighlightClear={[Function]}
onRemoveClick={[Function]}
/>
</div>
`;
5 changes: 4 additions & 1 deletion packages/pelagos/src/listInput/ListInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import './ListInput.less';
/** An input box for a list of values. */
const ListInput = ({
id,
className,
label,
required,
emptyText,
Expand Down Expand Up @@ -152,7 +153,7 @@ const ListInput = ({
const helperId = `${id}-helper`;
const errorId = `${id}-error`;
return (
<div className="ListInput">
<div className={`ListInput${className ? ` ${className}` : ''}`}>
<div className="sr-only" aria-live="assertive" ref={liveRef} />
<LabelLine id={labelId} htmlFor={id} text={label} required={required} error={!!error} />
<ComboBox
Expand Down Expand Up @@ -195,6 +196,8 @@ const ListInput = ({
ListInput.propTypes = {
/** The component id. */
id: PropTypes.string,
/** The component class name(s). */
className: PropTypes.string,
/** The label text. */
label: PropTypes.string,
/** Whether the field is required. */
Expand Down

0 comments on commit 806d9c9

Please sign in to comment.