Skip to content

Commit

Permalink
only set textbox if necessary (fix UWU-110), fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Aug 10, 2024
1 parent b8a259f commit 6fcf81b
Show file tree
Hide file tree
Showing 3 changed files with 4,945 additions and 4,062 deletions.
5 changes: 3 additions & 2 deletions packages/shelter-ui-test/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* @refresh reload */
import { render } from "solid-js/web";

import { initToasts } from "@uwu/shelter-ui";
import { initToasts, injectInternalStyles } from "@uwu/shelter-ui";

import "shelter-ui/compat.css";
import "@uwu/shelter-ui/compat.css";
import "./index.css";
import App from "./App";

const root = document.getElementById("root");

initToasts(document.body);
injectInternalStyles();

render(() => <App />, root!);
17 changes: 14 additions & 3 deletions packages/shelter-ui/src/textbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from "solid-js";
import { Component, createEffect } from "solid-js";
import { css, classes } from "./textbox.tsx.scss";
import { focusring } from "./focusring";
import { ensureInternalStyle } from "./internalstyles";
Expand All @@ -14,12 +14,18 @@ export const TextBox: Component<{
}> = (props) => {
ensureInternalStyle(css);

let r: HTMLInputElement;
createEffect(() => {
// only set value if it changed, to avoid unnecessary resets of scroll position from doing value = value
if (props.value !== r?.value && r) r.value = props.value;
});

return (
<input
use:focusring
class={classes.tbox}
type="text"
value={props.value}
ref={r}
placeholder={props.placeholder}
maxlength={props.maxLength ?? 999}
id={props.id}
Expand All @@ -43,6 +49,11 @@ export const TextArea: Component<{
}> = (props) => {
ensureInternalStyle(css);

let r: HTMLTextAreaElement;
createEffect(() => {
if (props.value !== r?.value && r) r.value = props.value;
});

return (
<textarea
use:focusring
Expand All @@ -52,7 +63,7 @@ export const TextArea: Component<{
[classes.ry]: props["resize-y"],
[classes.mono]: props.mono,
}}
value={props.value}
ref={r}
placeholder={props.placeholder}
id={props.id}
aria-labelledby={props["aria-label"]}
Expand Down
Loading

0 comments on commit 6fcf81b

Please sign in to comment.