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 #6394 from matrix-org/dbkr/exorcise_homeserver_che…
Browse files Browse the repository at this point in the history
…ckbox

Fix bug where 'other homeserver' would unfocus
  • Loading branch information
dbkr authored Jul 19, 2021
2 parents 4ef4f49 + 45fb0e9 commit 863f4d4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
8 changes: 7 additions & 1 deletion res/css/views/elements/_StyledRadioButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ limitations under the License.
width: $font-16px;
}

> input[type=radio] {
input[type=radio] {
// Remove the OS's representation
margin: 0;
padding: 0;
Expand Down Expand Up @@ -112,6 +112,12 @@ limitations under the License.
}
}
}

.mx_RadioButton_innerLabel {
display: flex;
position: relative;
top: 4px;
}
}

.mx_RadioButton_outlined {
Expand Down
3 changes: 2 additions & 1 deletion src/components/views/dialogs/ServerPickerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
className="mx_ServerPickerDialog_otherHomeserverRadio"
checked={!this.state.defaultChosen}
onChange={this.onOtherChosen}
childrenInLabel={false}
>
<Field
type="text"
className="mx_ServerPickerDialog_otherHomeserver"
label={_t("Other homeserver")}
onChange={this.onHomeserverChange}
onClick={this.onOtherChosen}
onFocus={this.onOtherChosen}
ref={this.fieldRef}
onValidate={this.onHomeserverValidate}
value={this.state.otherHomeserver}
Expand Down
30 changes: 25 additions & 5 deletions src/components/views/elements/StyledRadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";

interface IProps extends React.InputHTMLAttributes<HTMLInputElement> {
outlined?: boolean;
// If true (default), the children will be contained within a <label> element
// If false, they'll be in a div. Putting interactive components that have labels
// themselves in labels can cause strange bugs like https://github.com/vector-im/element-web/issues/18031
childrenInLabel?: boolean;
}

interface IState {
Expand All @@ -29,10 +33,11 @@ interface IState {
export default class StyledRadioButton extends React.PureComponent<IProps, IState> {
public static readonly defaultProps = {
className: '',
childrenInLabel: true,
};

public render() {
const { children, className, disabled, outlined, ...otherProps } = this.props;
const { children, className, disabled, outlined, childrenInLabel, ...otherProps } = this.props;
const _className = classnames(
'mx_RadioButton',
className,
Expand All @@ -42,12 +47,27 @@ export default class StyledRadioButton extends React.PureComponent<IProps, IStat
"mx_RadioButton_checked": this.props.checked,
"mx_RadioButton_outlined": outlined,
});
return <label className={_className}>

const radioButton = <React.Fragment>
<input type='radio' disabled={disabled} {...otherProps} />
{/* Used to render the radio button circle */}
<div><div /></div>
<div className="mx_RadioButton_content">{children}</div>
<div className="mx_RadioButton_spacer" />
</label>;
</React.Fragment>;

if (childrenInLabel) {
return <label className={_className}>
{radioButton}
<div className="mx_RadioButton_content">{children}</div>
<div className="mx_RadioButton_spacer" />
</label>;
} else {
return <div className={_className}>
<label className="mx_RadioButton_innerLabel">
{radioButton}
</label>
<div className="mx_RadioButton_content">{children}</div>
<div className="mx_RadioButton_spacer" />
</div>;
}
}
}

0 comments on commit 863f4d4

Please sign in to comment.