Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2484 from matrix-org/travis/select-field
Browse files Browse the repository at this point in the history
Support selects on Field
  • Loading branch information
turt2live authored Jan 23, 2019
2 parents 575cd1e + 2b3c8c4 commit b83227c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
12 changes: 8 additions & 4 deletions res/css/views/elements/_Field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ limitations under the License.
margin: 1em 0;
}

.mx_Field input {
.mx_Field input,
.mx_Field select {
font-weight: normal;
border-radius: 4px;
transition: border-color 0.25s;
border: 1px solid $input-border-color;
padding: 8px 9px;
}

.mx_Field input:focus {
.mx_Field input:focus,
.mx_Field select:focus {
outline: 0;
border-color: $input-focused-border-color;
}
Expand Down Expand Up @@ -61,7 +63,8 @@ limitations under the License.
}

.mx_Field input:focus + label,
.mx_Field input:not(:placeholder-shown) + label {
.mx_Field input:not(:placeholder-shown) + label,
.mx_Field select:focus + label {
transition:
font-size 0.25s ease-out 0s,
color 0.25s ease-out 0s,
Expand All @@ -72,6 +75,7 @@ limitations under the License.
background-color: $field-focused-label-bg-color;
}

.mx_Field input:focus + label {
.mx_Field input:focus + label,
.mx_Field select:focus + label {
color: $input-focused-border-color;
}
23 changes: 13 additions & 10 deletions src/components/views/elements/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,27 @@ export default class Field extends React.PureComponent {
label: PropTypes.string,
// The field's placeholder string.
placeholder: PropTypes.string,
// The type of field to create. Defaults to "input". Should be "input" or "select".
// To define options for a select, use <Field><option ... /></Field>
element: PropTypes.string,
// All other props pass through to the <input>.
}

render() {
const extraProps = Object.assign({}, this.props);

// Remove explicit props
delete extraProps.id;
delete extraProps.type;
delete extraProps.placeholder;
delete extraProps.label;
// Remove explicit properties that shouldn't be copied
delete extraProps.element;
delete extraProps.children;

// Set some defaults for the element
extraProps.type = extraProps.type || "text";

const element = this.props.element || "input";
const fieldInput = React.createElement(element, extraProps, this.props.children);

return <div className="mx_Field">
<input id={this.props.id}
type={this.props.type || "text"}
placeholder={this.props.placeholder}
{...extraProps}
/>
{fieldInput}
<label htmlFor={this.props.id}>{this.props.label}</label>
</div>;
}
Expand Down

0 comments on commit b83227c

Please sign in to comment.