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

#226 - restrict accepted mimetype #1242

Closed
Closed
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
11 changes: 10 additions & 1 deletion playground/samples/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ module.exports = {
format: "data-url",
},
},
filesAccept: {
type: "string",
format: "data-url",
title: "Single File with Accept attribute",
},
},
},
uiSchema: {
filesAccept: {
"ui:accept": ".pdf",
},
},
uiSchema: {},
formData: {},
};
6 changes: 2 additions & 4 deletions src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ import {

function ArrayFieldTitle({ TitleField, idSchema, title, required }) {
if (!title) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
}
const id = `${idSchema.$id}__title`;
return <TitleField id={id} title={title} required={required} />;
}

function ArrayFieldDescription({ DescriptionField, idSchema, description }) {
if (!description) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
}
const id = `${idSchema.$id}__description`;
return <DescriptionField id={id} description={description} />;
Expand Down
3 changes: 1 addition & 2 deletions src/components/fields/DescriptionField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import PropTypes from "prop-types";
function DescriptionField(props) {
const { id, description } = props;
if (!description) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
}
if (typeof description === "string") {
return (
Expand Down
12 changes: 4 additions & 8 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) {
function Label(props) {
const { label, required, id } = props;
if (!label) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
}
return (
<label className="control-label" htmlFor={id}>
Expand All @@ -88,8 +87,7 @@ function LabelInput(props) {
function Help(props) {
const { help } = props;
if (!help) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make these changes (returning null instead of <div>'s) in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning null instead of <div>'s PR is already merged. I dont know why this commits is showing here. Will remove that commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit messed up with the reverting part. So creating new PR #1246. Please delete this PR if possible.

}
if (typeof help === "string") {
return <p className="help-block">{help}</p>;
Expand All @@ -100,7 +98,7 @@ function Help(props) {
function ErrorList(props) {
const { errors = [] } = props;
if (errors.length === 0) {
return <div />;
return null;
}

return (
Expand Down Expand Up @@ -254,10 +252,8 @@ function SchemaFieldRender(props) {
const disabled = Boolean(props.disabled || uiSchema["ui:disabled"]);
const readonly = Boolean(props.readonly || uiSchema["ui:readonly"]);
const autofocus = Boolean(props.autofocus || uiSchema["ui:autofocus"]);

if (Object.keys(schema).length === 0) {
// See #312: Ensure compatibility with old versions of React.
return <div />;
return null;
}

const uiOptions = getUiOptions(uiSchema);
Expand Down
3 changes: 2 additions & 1 deletion src/components/widgets/FileWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FileWidget extends Component {
};

render() {
const { multiple, id, readonly, disabled, autofocus } = this.props;
const { multiple, id, readonly, disabled, autofocus, options } = this.props;
const { filesInfo } = this.state;
return (
<div>
Expand All @@ -104,6 +104,7 @@ class FileWidget extends Component {
defaultValue=""
autoFocus={autofocus}
multiple={multiple}
accept={options.accept}
/>
</p>
<FilesInfo filesInfo={filesInfo} />
Expand Down
13 changes: 10 additions & 3 deletions test/ArrayFieldTemplate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ describe("ArrayFieldTemplate", () => {
describe("Stateful ArrayFieldTemplate", () => {
class ArrayFieldTemplate extends PureComponent {
render() {
return <div>{this.props.items.map(item => item.element)}</div>;
return (
<div className="field-content">
{this.props.items.map((item, i) => (
<div key={i}>item.children</div>
))}
</div>
);
}
}

Expand All @@ -52,8 +58,9 @@ describe("ArrayFieldTemplate", () => {
formData,
ArrayFieldTemplate,
});

expect(node.querySelectorAll(".field-array div")).to.have.length.of(3);
expect(
node.querySelectorAll(".field-array .field-content div")
).to.have.length.of(3);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/SchemaField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("SchemaField", () => {
receivedProps = props;
}
render() {
return <div />;
return null;
}
},
},
Expand Down