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

Commit 863f4d4

Browse files
authored
Merge pull request #6394 from matrix-org/dbkr/exorcise_homeserver_checkbox
Fix bug where 'other homeserver' would unfocus
2 parents 4ef4f49 + 45fb0e9 commit 863f4d4

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

res/css/views/elements/_StyledRadioButton.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ limitations under the License.
4646
width: $font-16px;
4747
}
4848

49-
> input[type=radio] {
49+
input[type=radio] {
5050
// Remove the OS's representation
5151
margin: 0;
5252
padding: 0;
@@ -112,6 +112,12 @@ limitations under the License.
112112
}
113113
}
114114
}
115+
116+
.mx_RadioButton_innerLabel {
117+
display: flex;
118+
position: relative;
119+
top: 4px;
120+
}
115121
}
116122

117123
.mx_RadioButton_outlined {

src/components/views/dialogs/ServerPickerDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,14 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
205205
className="mx_ServerPickerDialog_otherHomeserverRadio"
206206
checked={!this.state.defaultChosen}
207207
onChange={this.onOtherChosen}
208+
childrenInLabel={false}
208209
>
209210
<Field
210211
type="text"
211212
className="mx_ServerPickerDialog_otherHomeserver"
212213
label={_t("Other homeserver")}
213214
onChange={this.onHomeserverChange}
214-
onClick={this.onOtherChosen}
215+
onFocus={this.onOtherChosen}
215216
ref={this.fieldRef}
216217
onValidate={this.onHomeserverValidate}
217218
value={this.state.otherHomeserver}

src/components/views/elements/StyledRadioButton.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
2020

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

2529
interface IState {
@@ -29,10 +33,11 @@ interface IState {
2933
export default class StyledRadioButton extends React.PureComponent<IProps, IState> {
3034
public static readonly defaultProps = {
3135
className: '',
36+
childrenInLabel: true,
3237
};
3338

3439
public render() {
35-
const { children, className, disabled, outlined, ...otherProps } = this.props;
40+
const { children, className, disabled, outlined, childrenInLabel, ...otherProps } = this.props;
3641
const _className = classnames(
3742
'mx_RadioButton',
3843
className,
@@ -42,12 +47,27 @@ export default class StyledRadioButton extends React.PureComponent<IProps, IStat
4247
"mx_RadioButton_checked": this.props.checked,
4348
"mx_RadioButton_outlined": outlined,
4449
});
45-
return <label className={_className}>
50+
51+
const radioButton = <React.Fragment>
4652
<input type='radio' disabled={disabled} {...otherProps} />
4753
{/* Used to render the radio button circle */}
4854
<div><div /></div>
49-
<div className="mx_RadioButton_content">{children}</div>
50-
<div className="mx_RadioButton_spacer" />
51-
</label>;
55+
</React.Fragment>;
56+
57+
if (childrenInLabel) {
58+
return <label className={_className}>
59+
{radioButton}
60+
<div className="mx_RadioButton_content">{children}</div>
61+
<div className="mx_RadioButton_spacer" />
62+
</label>;
63+
} else {
64+
return <div className={_className}>
65+
<label className="mx_RadioButton_innerLabel">
66+
{radioButton}
67+
</label>
68+
<div className="mx_RadioButton_content">{children}</div>
69+
<div className="mx_RadioButton_spacer" />
70+
</div>;
71+
}
5272
}
5373
}

0 commit comments

Comments
 (0)