diff --git a/res/css/_components.scss b/res/css/_components.scss
index f3b07255ae..6f66a8c15e 100644
--- a/res/css/_components.scss
+++ b/res/css/_components.scss
@@ -85,6 +85,7 @@
@import "./views/elements/_InlineSpinner.scss";
@import "./views/elements/_ManageIntegsButton.scss";
@import "./views/elements/_MemberEventListSummary.scss";
+@import "./views/elements/_PowerSelector.scss";
@import "./views/elements/_ProgressBar.scss";
@import "./views/elements/_ReplyThread.scss";
@import "./views/elements/_ResizeHandle.scss";
diff --git a/res/css/views/elements/_PowerSelector.scss b/res/css/views/elements/_PowerSelector.scss
new file mode 100644
index 0000000000..69f3a8eebb
--- /dev/null
+++ b/res/css/views/elements/_PowerSelector.scss
@@ -0,0 +1,25 @@
+/*
+Copyright 2019 New Vector Ltd.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+.mx_PowerSelector {
+ width: 100%;
+}
+
+.mx_PowerSelector .mx_Field select,
+.mx_PowerSelector .mx_Field input {
+ width: 100%;
+ box-sizing: border-box;
+}
diff --git a/src/components/views/elements/PowerSelector.js b/src/components/views/elements/PowerSelector.js
index d1f102d9fe..83b8711bef 100644
--- a/src/components/views/elements/PowerSelector.js
+++ b/src/components/views/elements/PowerSelector.js
@@ -20,6 +20,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import * as Roles from '../../../Roles';
import { _t } from '../../../languageHandler';
+import Field from "./Field";
module.exports = React.createClass({
displayName: 'PowerSelector',
@@ -32,19 +33,15 @@ module.exports = React.createClass({
// Default user power level for the room
usersDefault: PropTypes.number.isRequired,
- // if true, the should be a 'controlled' form element and updated by React
- // to reflect the current value, rather than left freeform.
- // MemberInfo uses controlled; RoomSettings uses non-controlled.
- //
- // ignored if disabled is truthy. false by default.
- controlled: PropTypes.bool,
-
// should the user be able to change the value? false by default.
disabled: PropTypes.bool,
onChange: PropTypes.func,
// Optional key to pass as the second argument to `onChange`
powerLevelKey: PropTypes.string,
+
+ // The name to annotate the selector with
+ label: PropTypes.string,
},
getInitialState: function() {
@@ -52,6 +49,9 @@ module.exports = React.createClass({
levelRoleMap: {},
// List of power levels to show in the drop-down
options: [],
+
+ customValue: this.props.value,
+ selectValue: 0,
};
},
@@ -77,61 +77,50 @@ module.exports = React.createClass({
return l === undefined || l <= newProps.maxValue;
});
+ const isCustom = levelRoleMap[newProps.value] === undefined;
+
this.setState({
levelRoleMap,
options,
- custom: levelRoleMap[newProps.value] === undefined,
+ custom: isCustom,
+ customLevel: newProps.value,
+ selectValue: isCustom ? "SELECT_VALUE_CUSTOM" : newProps.value,
});
},
onSelectChange: function(event) {
- this.setState({ custom: event.target.value === "SELECT_VALUE_CUSTOM" });
- if (event.target.value !== "SELECT_VALUE_CUSTOM") {
+ const isCustom = event.target.value === "SELECT_VALUE_CUSTOM";
+ if (isCustom) {
+ this.setState({custom: true});
+ } else {
this.props.onChange(event.target.value, this.props.powerLevelKey);
+ this.setState({selectValue: event.target.value});
}
},
+ onCustomChange: function(event) {
+ this.setState({customValue: event.target.value});
+ },
+
onCustomBlur: function(event) {
- this.props.onChange(parseInt(this.refs.custom.value), this.props.powerLevelKey);
+ this.props.onChange(parseInt(this.state.customValue), this.props.powerLevelKey);
},
onCustomKeyDown: function(event) {
- if (event.key == "Enter") {
- this.props.onChange(parseInt(this.refs.custom.value), this.props.powerLevelKey);
+ if (event.key === "Enter") {
+ this.props.onChange(parseInt(this.state.customValue), this.props.powerLevelKey);
}
},
render: function() {
- let customPicker;
+ let picker;
if (this.state.custom) {
- if (this.props.disabled) {
- customPicker = { _t(
- "Custom of %(powerLevel)s",
- { powerLevel: this.props.value },
- ) };
- } else {
- customPicker = =
- ;
- }
- }
-
- let selectValue;
- if (this.state.custom) {
- selectValue = "SELECT_VALUE_CUSTOM";
- } else {
- selectValue = this.state.levelRoleMap[this.props.value] ?
- this.props.value : "SELECT_VALUE_CUSTOM";
- }
- let select;
- if (this.props.disabled) {
- select = { this.state.levelRoleMap[selectValue] };
+ picker = (
+
{ eventType }
},
- );
+ label = _t("Send %(eventType)s events", {eventType});
}
return (
{_t('Select the roles required to change various parts of the room')}
{powerSelectors} {eventPowerSelectors}