Commit 4b7404c7 by Madhankumar

textarea height issue

parent 5a52d8a6
{ {
"task": [ "task": [
{ {
"title": "Travel to head office", "title": "",
"isCompleted": false, "isCompleted": false,
"id": 1 "id": 1
}, },
{ {
"title": "Buy food", "title": "",
"isCompleted": true, "isCompleted": false,
"id": 2 "id": 2
} }
] ]
......
...@@ -18,9 +18,9 @@ export function TodoProvider({ children }) { ...@@ -18,9 +18,9 @@ export function TodoProvider({ children }) {
} }
} }
//UPDATE METHOD //UPDATE METHOD
async function updateTodo({ id, ...item }) { async function updateTodo({ id, title, isCompleted }) {
try { try {
const response = await api.updateTodo({ id, ...item }); const response = await api.updateTodo({ id, title, isCompleted });
setTodo(response); setTodo(response);
} catch (err) { } catch (err) {
toast.error(err.message); toast.error(err.message);
......
import "./layout.css"; import "./layout.css";
function Layout({ count, ...props }) { function Layout({ count, ...props }) {
console.log(props); const todoCount = count > 1 ? "Todos" : "Todo";
return ( return (
<div className="container"> <div className="container">
<h2> <h1>
You have {count} {count > 1 ? "Todos" : "Todo"} You have {count} {todoCount}
</h2> </h1>
{/* inner section that contain (tasklist and forms) */} {/* inner section that contain (tasklist and forms) */}
<div {...props}></div> <div {...props}></div>
</div> </div>
......
.container { .container {
min-height: 40vh; min-height: 40dvh;
height: auto;
margin-inline: auto; margin-inline: auto;
background: white; background: white;
position: relative; position: relative;
} }
.container h2 { .container h1 {
box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px; box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px;
border: none; border: none;
text-align: center; text-align: center;
padding: 1.3rem 0px; padding: 1.3rem 0px;
margin: 0; margin: 0;
position: relative; position: relative;
font-size: 25px;
z-index: 1; z-index: 1;
} }
h3 { h3 {
...@@ -24,6 +23,12 @@ h3 { ...@@ -24,6 +23,12 @@ h3 {
} }
@media screen and (min-width: 1024px) { @media screen and (min-width: 1024px) {
.container { .container {
width: 40dvw; min-width: 40dvw;
}
}
@media screen and (min-width: 1550px) {
.container {
min-width: 30dvw;
} }
} }
...@@ -8,7 +8,7 @@ function Form({ onSubmit }) { ...@@ -8,7 +8,7 @@ function Form({ onSubmit }) {
const handleSubmit = (e) => { const handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
onSubmit({ title }); onSubmit({ title });
//setTitle(""); setTitle("");
}; };
return ( return (
......
...@@ -23,21 +23,35 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) { ...@@ -23,21 +23,35 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
// (useCallback)---> to avoid calling the checkbox component without any action applied on checkbox // (useCallback)---> to avoid calling the checkbox component without any action applied on checkbox
const handleChange = useCallback(() => { const handleChange = useCallback(() => {
setIsCheck(!ischeck); setIsCheck(!ischeck);
onChange({ id, title, isCompleted: !ischeck }); onChange({ id, isCompleted: !ischeck });
toast.success( // toast(`${!ischeck ? "Task completed" : "Task not completed"}`, "success");
`${!ischeck ? "Task completed" : "Task not completed"}`,
"success"
);
}, [ischeck]); }, [ischeck]);
const handleContent = (e) => { const handleContent = (e) => {
setDebounceTitle(e.target.value); setDebounceTitle(e.target.value);
const textarea = document.querySelector("textarea"); const textareaRef = textarea_ref.current;
//calculate the height of content based on scrollheight
textarea.addEventListener("keyup", (e) => { textareaRef.addEventListener("input", function () {
let scheight = e.target.scrollHeight; this.style.height = "auto"; // Reset the height to auto to calculate the correct scrollHeight
textarea.style.height = `${scheight}px`; const scrollHeight = this.scrollHeight;
if (this.scrollTop === 0) {
this.style.height = `${scrollHeight}px`;
} else {
// If there is overflow (a new line is created), increase the height
this.style.height = `${scrollHeight + this.scrollTop}px`;
}
}); });
// Optional: To ensure the textarea resizes initially if there's content
textareaRef.dispatchEvent(new Event("input"));
//const textarea = document.querySelector("textarea");
//calculate the height of content based on scrollheight
// textarea.addEventListener("keyup", (e) => {
// let scheight = e.target.scrollHeight;
// textarea.style.height = `${scheight}px`;
// });
}; };
//debounce //debounce
...@@ -45,11 +59,10 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) { ...@@ -45,11 +59,10 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
//checking the content height and set on page load //checking the content height and set on page load
const scrollHeight = textarea_ref.current.scrollHeight; const scrollHeight = textarea_ref.current.scrollHeight;
textarea_ref.current.style.height = `${scrollHeight}px`; textarea_ref.current.style.height = `${scrollHeight}px`;
//after 2 second it will execute //after 2 second it will execute
const handler = setTimeout(() => { const handler = setTimeout(() => {
if (textarea_ref.current.value !== title) { if (textarea_ref.current.value !== title) {
onChange({ id, title: debouncetitle, isCompleted: !ischeck }); onChange({ id, title: debouncetitle });
toast.success("Task updated"); toast.success("Task updated");
} }
}, 2000); }, 2000);
...@@ -71,7 +84,6 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) { ...@@ -71,7 +84,6 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
<textarea <textarea
ref={textarea_ref} ref={textarea_ref}
className={`${ischeck ? "strike-through" : ""}`} className={`${ischeck ? "strike-through" : ""}`}
contentEditable={true}
value={debouncetitle} value={debouncetitle}
onChange={handleContent} onChange={handleContent}
// disabled={ischeck} // disabled={ischeck}
......
.task-section { .task-section {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0.3rem 0.8rem; padding: 0.5rem 1rem 0.4rem 1rem;
justify-content: space-between; justify-content: space-between;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
/* box-shadow: rgba(0, 0, 0, 0.06) 0px 2px 4px 0px inset; */ /* box-shadow: rgba(0, 0, 0, 0.06) 0px 2px 4px 0px inset; */
clip-path: inset(0 -100vmax); clip-path: inset(0 -100vmax);
} }
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
.task-section > div { .task-section > div {
display: flex; display: flex;
align-items: center; align-items: center;
height: auto;
width: 90%; width: 90%;
} }
.fa-close { .fa-close {
...@@ -34,8 +36,9 @@ input:focus { ...@@ -34,8 +36,9 @@ input:focus {
resize: none; resize: none;
border: none; border: none;
outline: none; outline: none;
margin: 20px 0px 0px 5px; position: relative;
padding: 0; top: 10px;
margin-left: 0.4rem;
font-size: 17px; font-size: 17px;
color: #8e8d8d; color: #8e8d8d;
font-family: "Open Sans", sans-serif; font-family: "Open Sans", sans-serif;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment