Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix focus ring styles for radio button toggles #1772 #1773

Merged
merged 8 commits into from
Jul 4, 2023
54 changes: 33 additions & 21 deletions src/shared/components/common/data-type-select.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { randomStr } from "@utils/helpers";
import classNames from "classnames";
import { Component, linkEvent } from "inferno";
import { DataType } from "../../interfaces";
import { I18NextService } from "../../services";
Expand All @@ -15,6 +17,8 @@ export class DataTypeSelect extends Component<
DataTypeSelectProps,
DataTypeSelectState
> {
private id = `listing-type-input-${randomStr()}`;

state: DataTypeSelectState = {
type_: this.props.type_,
};
Expand All @@ -31,33 +35,41 @@ export class DataTypeSelect extends Component<

render() {
return (
<div className="data-type-select btn-group btn-group-toggle flex-wrap">
<div
className="data-type-select btn-group btn-group-toggle flex-wrap"
role="group"
>
<input
id={`${this.id}-posts`}
type="radio"
className="btn-check"
value={DataType.Post}
checked={this.state.type_ == DataType.Post}
jsit marked this conversation as resolved.
Show resolved Hide resolved
onChange={linkEvent(this, this.handleTypeChange)}
/>
<label
className={`pointer btn btn-outline-secondary
${this.state.type_ == DataType.Post && "active"}
`}
htmlFor={`${this.id}-posts`}
className={classNames("pointer btn btn-outline-secondary", {
active: this.state.type_ === DataType.Post,
})}
>
<input
type="radio"
className="btn-check"
value={DataType.Post}
checked={this.state.type_ == DataType.Post}
onChange={linkEvent(this, this.handleTypeChange)}
/>
{I18NextService.i18n.t("posts")}
</label>

<input
id={`${this.id}-comments`}
type="radio"
className="btn-check"
value={DataType.Comment}
checked={this.state.type_ == DataType.Comment}
jsit marked this conversation as resolved.
Show resolved Hide resolved
onChange={linkEvent(this, this.handleTypeChange)}
/>
<label
className={`pointer btn btn-outline-secondary ${
this.state.type_ == DataType.Comment && "active"
}`}
htmlFor={`${this.id}-comments`}
className={classNames("pointer btn btn-outline-secondary", {
active: this.state.type_ === DataType.Comment,
})}
>
<input
type="radio"
className="btn-check"
value={DataType.Comment}
checked={this.state.type_ == DataType.Comment}
onChange={linkEvent(this, this.handleTypeChange)}
/>
{I18NextService.i18n.t("comments")}
</label>
</div>
Expand Down
77 changes: 45 additions & 32 deletions src/shared/components/common/listing-type-select.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { randomStr } from "@utils/helpers";
import classNames from "classnames";
import { Component, linkEvent } from "inferno";
import { ListingType } from "lemmy-js-client";
import { I18NextService, UserService } from "../../services";
Expand Down Expand Up @@ -38,60 +39,72 @@ export class ListingTypeSelect extends Component<

render() {
return (
<div className="listing-type-select btn-group btn-group-toggle flex-wrap">
<div
className="listing-type-select btn-group btn-group-toggle flex-wrap"
role="group"
>
{this.props.showSubscribed && (
<label
title={I18NextService.i18n.t("subscribed_description")}
className={`btn btn-outline-secondary
${this.state.type_ == "Subscribed" && "active"}
${!UserService.Instance.myUserInfo ? "disabled" : "pointer"}
`}
>
<>
<input
id={`${this.id}-subscribed`}
type="radio"
className="btn-check"
value={"Subscribed"}
checked={this.state.type_ == "Subscribed"}
checked={this.state.type_ === "Subscribed"}
onChange={linkEvent(this, this.handleTypeChange)}
disabled={!UserService.Instance.myUserInfo}
/>
{I18NextService.i18n.t("subscribed")}
</label>
<label
htmlFor={`${this.id}-subscribed`}
title={I18NextService.i18n.t("subscribed_description")}
className={classNames("btn btn-outline-secondary", {
active: this.state.type_ === "Subscribed",
disabled: !UserService.Instance.myUserInfo,
pointer: UserService.Instance.myUserInfo,
})}
>
{I18NextService.i18n.t("subscribed")}
</label>
</>
)}
{this.props.showLocal && (
<label
title={I18NextService.i18n.t("local_description")}
className={`pointer btn btn-outline-secondary ${
this.state.type_ == "Local" && "active"
}`}
>
<>
<input
id={`${this.id}-local`}
type="radio"
className="btn-check"
value={"Local"}
checked={this.state.type_ == "Local"}
checked={this.state.type_ === "Local"}
onChange={linkEvent(this, this.handleTypeChange)}
/>
{I18NextService.i18n.t("local")}
</label>
<label
htmlFor={`${this.id}-local`}
title={I18NextService.i18n.t("local_description")}
className={classNames("pointer btn btn-outline-secondary", {
active: this.state.type_ === "Local",
})}
>
{I18NextService.i18n.t("local")}
</label>
</>
)}
<input
id={`${this.id}-all`}
type="radio"
className="btn-check"
value={"All"}
checked={this.state.type_ === "All"}
onChange={linkEvent(this, this.handleTypeChange)}
/>
<label
title={I18NextService.i18n.t("all_description")}
className={`pointer btn btn-outline-secondary ${
(this.state.type_ == "All" && "active") ||
(!this.props.showLocal && this.state.type_ == "Local" && "active")
}`}
htmlFor={`${this.id}-all`}
className={classNames("pointer btn btn-outline-secondary", {
active:
this.state.type_ === "All" ||
(!this.props.showLocal && this.state.type_) === "Local",
})}
>
<input
id={`${this.id}-all`}
type="radio"
className="btn-check"
value={"All"}
checked={this.state.type_ == "All"}
onChange={linkEvent(this, this.handleTypeChange)}
/>
{I18NextService.i18n.t("all")}
</label>
</div>
Expand Down
147 changes: 84 additions & 63 deletions src/shared/components/person/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
setIsoData,
updatePersonBlock,
} from "@utils/app";
import { capitalizeFirstLetter } from "@utils/helpers";
import { capitalizeFirstLetter, randomStr } from "@utils/helpers";
import { RouteDataResponse } from "@utils/types";
import classNames from "classnames";
import { Component, linkEvent } from "inferno";
import {
AddAdmin,
Expand Down Expand Up @@ -283,97 +284,117 @@ export class Inbox extends Component<any, InboxState> {
}

unreadOrAllRadios() {
const radioId = randomStr();

return (
<div className="btn-group btn-group-toggle flex-wrap">
<div className="btn-group btn-group-toggle flex-wrap" role="group">
<input
id={`${radioId}-unread`}
type="radio"
className="btn-check"
value={UnreadOrAll.Unread}
checked={this.state.unreadOrAll === UnreadOrAll.Unread}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.unreadOrAll == UnreadOrAll.Unread && "active"}
`}
htmlFor={`${radioId}-unread`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.unreadOrAll === UnreadOrAll.Unread,
})}
>
<input
type="radio"
className="btn-check"
value={UnreadOrAll.Unread}
checked={this.state.unreadOrAll == UnreadOrAll.Unread}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
{I18NextService.i18n.t("unread")}
</label>

<input
id={`${radioId}-all`}
type="radio"
className="btn-check"
value={UnreadOrAll.All}
checked={this.state.unreadOrAll === UnreadOrAll.All}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.unreadOrAll == UnreadOrAll.All && "active"}
`}
htmlFor={`${radioId}-all`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.unreadOrAll === UnreadOrAll.All,
})}
>
<input
type="radio"
className="btn-check"
value={UnreadOrAll.All}
checked={this.state.unreadOrAll == UnreadOrAll.All}
onChange={linkEvent(this, this.handleUnreadOrAllChange)}
/>
{I18NextService.i18n.t("all")}
</label>
</div>
);
}

messageTypeRadios() {
const radioId = randomStr();

return (
<div className="btn-group btn-group-toggle flex-wrap">
<div className="btn-group btn-group-toggle flex-wrap" role="group">
<input
id={`${radioId}-all`}
type="radio"
className="btn-check"
value={MessageType.All}
checked={this.state.messageType === MessageType.All}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.All && "active"}
`}
htmlFor={`${radioId}-all`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.messageType === MessageType.All,
})}
>
<input
type="radio"
className="btn-check"
value={MessageType.All}
checked={this.state.messageType == MessageType.All}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{I18NextService.i18n.t("all")}
</label>

<input
id={`${radioId}-replies`}
type="radio"
className="btn-check"
value={MessageType.Replies}
checked={this.state.messageType === MessageType.Replies}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.Replies && "active"}
`}
htmlFor={`${radioId}-replies`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.messageType === MessageType.Replies,
})}
>
<input
type="radio"
className="btn-check"
value={MessageType.Replies}
checked={this.state.messageType == MessageType.Replies}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{I18NextService.i18n.t("replies")}
</label>

<input
id={`${radioId}-mentions`}
type="radio"
className="btn-check"
value={MessageType.Mentions}
checked={this.state.messageType === MessageType.Mentions}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.Mentions && "active"}
`}
htmlFor={`${radioId}-mentions`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.messageType === MessageType.Mentions,
})}
>
<input
type="radio"
className="btn-check"
value={MessageType.Mentions}
checked={this.state.messageType == MessageType.Mentions}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{I18NextService.i18n.t("mentions")}
</label>

<input
id={`${radioId}-messages`}
type="radio"
className="btn-check"
value={MessageType.Messages}
checked={this.state.messageType === MessageType.Messages}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
<label
className={`btn btn-outline-secondary pointer
${this.state.messageType == MessageType.Messages && "active"}
`}
htmlFor={`${radioId}-messages`}
className={classNames("btn btn-outline-secondary pointer", {
active: this.state.messageType === MessageType.Messages,
})}
>
<input
type="radio"
className="btn-check"
value={MessageType.Messages}
checked={this.state.messageType == MessageType.Messages}
onChange={linkEvent(this, this.handleMessageTypeChange)}
/>
{I18NextService.i18n.t("messages")}
</label>
</div>
Expand Down