Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#785 class name for select field #795

Merged
merged 5 commits into from
Sep 9, 2020
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
43 changes: 43 additions & 0 deletions packages/uniforms-bootstrap4/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,49 @@ test('<SelectField> - renders a label', () => {
);
});

test('<SelectField> - renders a select with class "bg-red" beside "form-group"', () => {
const element = <SelectField name="x" className="bg-red" />;
const wrapper = mount(
element,
createContext({ x: { type: String, allowedValues: ['a', 'b'] } }),
);
expect(wrapper.find('.bg-red.form-group')).toHaveLength(1);
});

test('<SelectField> - renders a disabled select', () => {
const element = <SelectField name="x" disabled />;
const wrapper = mount(
element,
createContext({ x: { type: String, allowedValues: ['a', 'b'] } }),
);
expect(wrapper.find('select').prop('disabled')).toEqual(true);
});

test('<SelectField> - renders a required select', () => {
const element = <SelectField name="x" required />;
const wrapper = mount(
element,
createContext({ x: { type: String, allowedValues: ['a', 'b'] } }),
);
expect(wrapper.find('.form-group.required')).toHaveLength(1);
});

test('<SelectField> - renders am error massge in select', () => {
const element = (
<SelectField
name="x"
showInlineError
error={new Error()}
errorMessage="Error"
/>
);
const wrapper = mount(
element,
createContext({ x: { type: String, allowedValues: ['a', 'b'] } }),
);
expect(wrapper.find('.form-text.text-danger')).toHaveLength(1);
});

test('<SelectField> - renders a wrapper with unknown props', () => {
const element = <SelectField name="x" data-x="x" data-y="y" data-z="z" />;
const wrapper = mount(
Expand Down
12 changes: 8 additions & 4 deletions packages/uniforms-bootstrap4/src/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export type SelectFieldProps = HTMLFieldProps<
function Select({
allowedValues,
checkboxes,
className,
disabled,
error,
errorMessage,
fieldType,
id,
inline,
Expand All @@ -41,13 +39,19 @@ function Select({
onChange,
placeholder,
required,
showInlineError,
transform,
value,
...props
}: SelectFieldProps) {
return wrapField(
{ ...props, id, label },
{
...props,
disabled,
error,
id,
label,
required,
},
checkboxes || fieldType === Array ? (
allowedValues?.map(item => (
<div
Expand Down