Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Commit

Permalink
Updates MDL controls to allow remote updates. Closes #65. (#66)
Browse files Browse the repository at this point in the history
* Updates MDL controls to allow remote updates. Closes #65.

* Updates react ref to use callback.

* Fixes mispelling.

* Removes unnecessary @OverRide tag.
  • Loading branch information
chriscox authored Jan 18, 2017
1 parent 46f2410 commit 823d8e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ui/controls/RadioListControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { IStringControlProps } from "./controlProps";
*/
export class RadioListControl extends React.Component<IStringControlProps, void> {

/** Array of MDL components. */
radioItems: HTMLLabelElement[] = [];

/** Handles the update event for this control. */
onChange = (event: React.FormEvent<HTMLInputElement>): void => {
this.props.updateVariable(
Expand All @@ -39,6 +42,13 @@ export class RadioListControl extends React.Component<IStringControlProps, void>
return nextProps.variable !== this.props.variable;
}

componentDidUpdate() {
const { limitedToValues, selectedValue } = this.props.variable;
let index = limitedToValues.indexOf(selectedValue);
let materialRadio = this.radioItems[index]["MaterialRadio"];
materialRadio.check();
}

/** @override */
render() {
const {
Expand All @@ -54,7 +64,9 @@ export class RadioListControl extends React.Component<IStringControlProps, void>
<span className={CSS.MDL_PRIMARY}>{title}</span>
<span className={CSS.MDL_SECONDARY}>
{limitedToValues.map((value: string, i: number) => (
<label className={`${CSS.RMX_RADIO_LIST_ITEM} mdl-radio mdl-js-radio mdl-js-ripple-effect`}
<label
ref={item => this.radioItems[i] = item}
className={`${CSS.RMX_RADIO_LIST_ITEM} mdl-radio mdl-js-radio mdl-js-ripple-effect`}
htmlFor={`${id}-${i}`} key={value}
>
<input type="radio" id={`${id}-${i}`}
Expand Down
9 changes: 9 additions & 0 deletions src/ui/controls/SwitchControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { IBooleanControlProps } from "./controlProps";
*/
export class SwitchControl extends React.Component<IBooleanControlProps, void> {

/** The MDL switch component. */
switchControl: HTMLLabelElement;

/** Handles the update event for this control. */
onChange = (event: React.FormEvent<HTMLInputElement>): void => {
const { selectedValue } = this.props.variable;
Expand All @@ -37,6 +40,11 @@ export class SwitchControl extends React.Component<IBooleanControlProps, void> {
return nextProps.variable !== this.props.variable;
}

componentDidUpdate() {
let materialSwitch = this.switchControl["MaterialSwitch"];
this.props.variable.selectedValue ? materialSwitch.on() : materialSwitch.off();
}

/** @override */
render() {
const {
Expand All @@ -51,6 +59,7 @@ export class SwitchControl extends React.Component<IBooleanControlProps, void> {
<span className={CSS.MDL_PRIMARY}>{title}</span>
<span className={CSS.MDL_SECONDARY}>
<label
ref={item => this.switchControl = item}
className="mdl-switch mdl-js-switch mdl-js-ripple-effect"
htmlFor={id}
>
Expand Down

0 comments on commit 823d8e2

Please sign in to comment.