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

Bug/ onCardUpdate does not fire #29

Merged
merged 5 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-guests-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-trello-ts": patch
---

bug/ onCardUpdate should fire - #26
6 changes: 6 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
with:
version: 8
run_install: false

- name: Cypress install
uses: cypress-io/github-action@v6
with:
# Disable running of tests within install job
runTests: false

- name: Get pnpm store directory
id: pnpm-cache
Expand Down
184 changes: 98 additions & 86 deletions packages/react-trello-ts/src/widgets/InlineInput.tsx
Original file line number Diff line number Diff line change
@@ -1,92 +1,104 @@
import React, {
FC,
PropsWithChildren,
useEffect,
useRef,
useState,
} from "react";
import { InlineInput as _InlineInput } from "../styles/Base";
import autosize from "autosize";
import React, {FC, useEffect, useRef, useState} from 'react'
import {InlineInput as _InlineInput} from '@/styles/Base'
import autosize from 'autosize'

interface InlineInputProps {
onSave?: (inputValue: string) => void;
onCancel?: () => void;
border?: boolean;
placeholder?: string;
value?: string;
autoFocus?: boolean;
resize?: "vertical" | "horizontal" | "none";
onSave?: (inputValue: string) => void
onCancel?: () => void
border?: boolean
placeholder?: string
value?: string
autoFocus?: boolean
resize?: 'none' | 'vertical' | 'horizontal'
}

export const InlineInput: FC<PropsWithChildren<InlineInputProps>> = ({
autoFocus = false,
border = false,
onSave,
onCancel,
placeholder = "",
resize = "none",
value = "",
export const InlineInput: FC<InlineInputProps> = ({
autoFocus = false,
border = false,
onSave = () => {},
onCancel = () => {},
placeholder = '',
value = '',
resize = 'none'
}) => {
const inputRef = useRef<HTMLTextAreaElement>();
const [inputValue, setInputValue] = useState(value);
const onFocus = (e: React.FocusEvent<HTMLTextAreaElement>) => {
e.target.select();
};
const onMouseDown = (e: React.MouseEvent<HTMLTextAreaElement>) => {
if (document.activeElement !== e.target) {
e.preventDefault();
inputRef.current.focus();
}
};
const onBlur = () => {
if (inputValue !== value) {
onSave(inputValue);
}
};
const [inputValue, setInputValue] = useState(value)
const inputRef = useRef<HTMLTextAreaElement | null>(null)

const onKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter") {
inputRef.current.blur();
e.preventDefault();
}
if (e.key === "Escape") {
setInputValue(value);
inputRef.current.blur();
e.preventDefault();
}
if (e.key === "Tab") {
if (inputValue.length === 0) {
onCancel();
}
inputRef.current.blur();
e.preventDefault();
}
};
const setRef = (ref: HTMLTextAreaElement) => {
inputRef.current = ref;
if (resize !== "none") {
autosize(inputRef);
}
};
useEffect(() => {
setInputValue(value);
}, [resize]);
return (
<_InlineInput
ref={setRef}
border={border}
onMouseDown={onMouseDown}
onFocus={onFocus}
onBlur={onBlur}
onKeyDown={onKeyDown}
placeholder={value.length === 0 ? undefined : placeholder}
defaultValue={value}
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
rows={1}
autoFocus={autoFocus}
/>
);
};
const onFocus = (e: React.FocusEvent<HTMLTextAreaElement>) => e.target.select()

const onMouseDown = (e: React.MouseEvent<HTMLTextAreaElement>) => {
if (document.activeElement !== e.target) {
e.preventDefault()
inputRef.current.focus()
}
}

const onBlur = () => {
updateValue()
}

const onKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
inputRef.current.blur()
e.preventDefault()
}
if (e.key === 'Escape') {
setValue(value)
inputRef.current.blur()
e.preventDefault()
}
if (e.key === 'Tab') {
if (inputValue.length === 0) {
onCancel()
}
inputRef.current.blur()
e.preventDefault()
}
}

const getValue = () => inputRef.current.value || ''
const setValue = (newValue: string) => {
if (inputRef.current) {
inputRef.current.value = newValue
}
}

const updateValue = () => {
if (getValue() !== value) {
onSave(getValue())
}
}

const setRef = (ref: HTMLTextAreaElement) => {
inputRef.current = ref
if (resize !== 'none') {
autosize(inputRef.current)
}
}

useEffect(
() => {
setInputValue(value)
},
[value]
)

return (
<_InlineInput
ref={setRef}
border={border}
onMouseDown={onMouseDown}
onFocus={onFocus}
onBlur={onBlur}
onKeyDown={onKeyDown}
placeholder={value.length === 0 ? undefined : placeholder}
defaultValue={value}
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
rows={1}
autoFocus={autoFocus}
/>
)
}
Loading