Skip to content

Commit

Permalink
fix: user input for tag editor and other misc inputs (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Nov 17, 2024
1 parent cc72f1a commit 1779f55
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/features/auth/login/login/PickLoginServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function PickLoginServer() {

<IonSearchbar
ref={searchbarRef}
enterkeyhint="go"
enterkeyhint="next"
placeholder="Enter URL or search for your server"
inputMode="url"
onKeyDown={(e) => {
Expand Down
9 changes: 3 additions & 6 deletions src/features/auth/login/pickJoinServer/PickJoinServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Login from "#/features/auth/login/login/Login";
import AppHeader from "#/features/shared/AppHeader";
import { DynamicDismissableModalContext } from "#/features/shared/DynamicDismissableModal";
import { isIosTheme } from "#/helpers/device";
import { blurOnEnter } from "#/helpers/dom";
import { isMinimumSupportedLemmyVersion } from "#/helpers/lemmy";
import { isValidHostname, stripProtocol } from "#/helpers/url";
import { defaultServersUntouched, getCustomServers } from "#/services/app";
Expand Down Expand Up @@ -349,13 +350,9 @@ export default function PickJoinServer() {
<StyledIonSearchbar
value={search}
onIonInput={(e) => setSearch(e.detail.value || "")}
onKeyDown={(e) => {
if (e.key !== "Enter") return;

if (e.target instanceof HTMLElement) e.target.blur();
}}
onKeyDown={blurOnEnter}
inputMode="url"
enterkeyhint="go"
enterkeyhint="done"
/>
<Filters
hasRecommended={hasRecommended}
Expand Down
6 changes: 3 additions & 3 deletions src/features/tags/UserTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const TagContainer = styled.span`
overflow: hidden;
text-overflow: ellipsis;
background: var(--bg, var(--lightroom-bg));
background: var(--lightroom-bg);
color: var(--ion-color-medium);
border-radius: 4px;
padding: 0 4px;
Expand Down Expand Up @@ -85,8 +86,7 @@ function SyncUserTag({ tag }: SyncUserTagProps) {
style={
tag.color
? {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
["--bg" as any]: tag.color,
background: tag.color,
color: getTextColorFor(tag.color),
}
: undefined
Expand Down
19 changes: 15 additions & 4 deletions src/features/tags/UserTagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useState } from "react";
import { Centered } from "#/features/auth/login/LoginNav";
import PersonLink from "#/features/labels/links/PersonLink";
import AppHeader from "#/features/shared/AppHeader";
import { blurOnEnter } from "#/helpers/dom";
import { getRemoteHandle } from "#/helpers/lemmy";

import { useAppDispatch, useAppSelector } from "../../store";
Expand Down Expand Up @@ -44,10 +45,14 @@ const UserText = styled(IonText)`
`;

const ColorIonInput = styled(IonInput)`
.native-wrapper {
.native-input {
max-width: 42px;
}
.input-clear-icon {
margin: 0 0 0 auto;
}
&& input {
appearance: none;
border-radius: 4px;
Expand Down Expand Up @@ -174,6 +179,12 @@ function UserTagModalContents({
clearInput
placeholder="Private user note"
value={tag.text}
inputMode="text"
autocapitalize="on"
autocorrect="on"
spellCheck
enterKeyHint="done"
onKeyDown={blurOnEnter}
onIonInput={(e) => {
setTag((tag) => {
const newTag = { ...tag, text: e.detail.value ?? "" };
Expand All @@ -191,9 +202,9 @@ function UserTagModalContents({
<IonItem>
<ColorIonInput
label="Color"
// TODO add Ionic support for color input
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type={"color" as any}
// @ts-expect-error -- add Ionic support for color input
type="color"
clearInput
value={tag.color}
onIonInput={(e) => {
setTag((tag) => {
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/dom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { KeyboardEvent } from "react";

import { ua } from "./device";

export const useScrollIntoViewWorkaround = ua.getEngine().name === "WebKit";
Expand Down Expand Up @@ -138,3 +140,9 @@ export function getSelectionHtml(selection: Selection): string {

return html;
}

export function blurOnEnter(e: KeyboardEvent) {
if (e.key !== "Enter") return;

if (e.target instanceof HTMLElement) e.target.blur();
}

0 comments on commit 1779f55

Please sign in to comment.