Editing feature for react - reactjs

I am implementing edit feature with react now. The problem is that I haven't found the good solution for this yet.
I want to make a view like below.
Both title and description text area are already written with default text.
This text is not placeholder.
If user click the button, User can edit the text.
I tried the below two packages but it is not perfect for my purpose.
TextareaAutosize
import TextareaAutosize from 'react-autosize-textarea';
TextareaAutosize has a value attribute. but if I use this, I can't edit the text in it. And the defaultValue seems not working.
Do you know how to put a default text value into TextareaAutosize component?
2.AvInput
import { AvForm, AvField, AvGroup, AvInput, AvRadioGroup, AvRadio } from 'availity-reactstrap-validation';
I think this is another good solution but the submit button seems not to be customized.
I should place the Edit button in the right-upper side of view.
But if I use this package, The submit button is placed at the bottom and it seems like it should be used tag.
Do you know how to connect my own submit button with AvInput?
The button is in other tags, not in its .
https://availity.github.io/availity-reactstrap-validation/components/avform/
<FormGroup>
<Button>Submit</Button>
</FormGroup>
other solution
If you have a better solution or experience, plz let me know.
Thank you in advance

I referred to the below answer and changed UX.
Submit form using a button outside the <form> tag
The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.
submit button seems to be included in the form tag.

Related

How can I find and click a button that has no text using React Testing Library?

Many React Testing Library examples show how to find and click a button using the getByText query, as in:
fireEvent.click(getByText("Create"))
OR
userEvent.click(getByText("Create"))
However, it's common to have buttons with no text and only SVG icons, like Material UI's icon buttons or floating action buttons. Is there a recommended way to query for and click buttons like these? For context, I'm using the higher-level events provided by the companion user-event library.
For icon buttons, add an aria-label attribute like below:
<button aria-label='edit'>
<edit-icon />
</button>
Then in your test, pass the accessible name when calling getByRole()
screen.getByRole('button', {
name: /edit/i
})
From the docs:
The accessible name is for simple cases equal to e.g. the label of a
form element, or the text content of a button, or the value of the
aria-label attribute.
There are several ways to query an element, without seeing your hierarchy of elements, it's hard to say. But, there are several ways to query an element, an alternative to using getByText() could be getByRole('button'). If you want to add a data-testid to the element you could use getByTestId(). There are some more available queries found here: https://testing-library.com/docs/dom-testing-library/api-queries
There are a bunch of different ways to do it, including everyone's favorite fallback, data-tested. But if you're using Material UI, you might be looking for the most "MUI" way to do this. Two ideas:
The MUI documentation shows all its buttons wrapped with a label element with an htmlFor property. You could do this and then use getByLabelText()
Your icon buttons probably have (and should!) a tooltip, and the tooltip text is probably coming from a title property. Then you can get the button with getByTitle().
For me non of above answers works, what is worked for me is:
screen.getByRole('button', { name: /<icon-file-name>/i });
In my case the button with only svg file.
The best possible way of finding an element is to simulate the most User oriented approach. So probably User expects the role button and then searches for an icon in your case. That's where semantic HTML plays a role for elements structure inside your component.
MUI buttons also implement a name attribute for some icon buttons used inside another component e.g. Select and I strongly recommend using this attribute for testing purpose.
Please remember that, your tests should be unaware of implementation, so identification should rely on name, role, label and other "natural" attributes. But if that is not possible using data-testid should be your last resort.
A very good overall approach (not only for icon buttons) is to specify a name property alongside role in getByRole query:
const listOpenButton = screen.getByRole("button", { name: /open/i });
Also a data-testid approach:
const listOpenButton = screen.getByTestId("myButtonId");

Issue with Chrome extension in ReactJS Redux Form

In my project, I am using Redux Form. I have Grammarly Chrome extension. There is textarea Field in my Form. When I Click on Textarea field the textarea field disappears and it appears on the side. If I change textarea field to text its working fine but I need textarea here. I post the screenshot for a better understanding of the problem. There is any way to overcome this problem.
Before clicking on textarea, the textarea display normally.
After Clicking on textarea, the textarea box appears on right side of the other fields.
Grammarly extension set inline styles for the textarea/contenteditable fields.
You need just check which styles are overwritten by extension and then just fix them by applying your styles.
Also, you can disable initialization of Grammarly extension by special attribute: data-enable-grammarly="false."
You can find more information here.

Customizing & Styling Angular X-Editable Popover Input

I'm using angular x-editable in my project for an editable popover. I've successfully made changes to the look of my confirmation button to an .svg I wanted to use and removed the Cancel button doing:
app.run(function(editableOptions, editableThemes) {
editableOptions.theme = 'default';
editableThemes[default].cancelTpl = '';
editableThemes[default].submitTpl = '<img class="popoverSubmitBtn"
src="images/confirmationBtn.svg" ng-click="$form.$submit()">';
});
However I am having issues when trying to change editableThemes[default].inputTpl. It seems like changes to inputTpl are not being registered for some reason. What I would like is for the input box that shows in the popover to have a circular 'x' button to clear the current input WITHIN the input text field.
This was actually default behavior in the original x-editable (see here at Twitter typeahead.js demo). While there is an equivalent to use editableOptions.displayClearButton=true, this creates an entire button next to the input box, much like the confirmation button, which is not what I want.
My plan was to use a directive here that provides the 'clear' button and use editableThemes[default].inputTpl = '<input type="text" reset-directive>'; but again, seems like its broken. Even this open issue here leads me to believe it was never working as intended.
Has anyone had any luck with this or knows of any workarounds that may help in my situation?
ALSO- a bit unrelated but on the topic of styling, how do I move the position of where the popover shows up? Currently it's smack-dab in the middle of where my cursor is when I click the text to activate popover, but I would like it a bit higher and to the right.
Got it working. For those with similar issues:
Styling for the popover can be controlled through xeditable.css found in the bower_components directory after installation
While inputTpl isn't functioning the way I expected, I added the
custom directive to the input field using e-* (i.e. e-my-directive) with no issues.

How to add a clear button to the auto complete field in material-ui

I am using Material-UIs AutoComplete Component (v0.15.4) to implement kind of a filter. To improve the user experience I want to add a clear button (Icon Button component?) inside or next to it which simply clears the current input (like in the pictures of the Google Specification for Auto-complete text fields).
Since the AutoComplete uses the TextField, I thought of giving an ListItem or MenuItem to the "value" of the TextField and use the rightIcon(Button). But the AutoComplete only allows String as "SearchText" (whic internaly is uses to fill the "value" field of the TextField).
So since I can not put an other component inside the "searchText" I end up with the idea of wrapping the AutoComplete inside a ListItem like this:
<ListItem
primaryText={<AutoComplete
dataSource={ dataSource }
filter={AutoComplete.fuzzyFilter}
hintText="Select Filter"
onNewRequest={this.handleSelect.bind(this)} />}
rightIconButton={<IconButton
onClick={this.handleClearClick.bind(this)}>
<ClearIcon />
</IconButton>}
/>
But this way the clear icon appears behind the auto complete input field and I do not really need/want the list (item).
Are there any other idea of solving this problem? Or is maybe the clear-function (or more generic "rightIconButton" field) planed for future version of Material-UI?
Working Pen: https://codepen.io/pranesh-r/pen/yawzbW?editors=0010
Consider using a controlled component here. Set the user input to the state using onUpdateInput event and pass the value in the state to the <AutoComplete/> using searchText props. When the user clicks clear button, clear the input in the state.
P.S. I've used FlatButton as the clear. You can also use IconButton.
Hope this helps!

Hide checker (if true) in a interactive PDF with custom checkbox created with inDesign

I got a problem with checkbox field using Adobe Indesign.
I want an image to become my checkbox button and also change the image after clicking. Unfortunately, after clicking on this button the image changes properly, but it also adds checker (check sign) in the middle of the picture. Can't see to overcome this.
It looks like this:
checkmarks
I would consider using two buttons for that. One hiding the opposite and vice-versa. Here is an example:
And here is a link to the package :
http://www.filedropper.com/dossieronoff
And here is a link to a demo PDF:
http://www.filedropper.com/onoff

Resources