onPreview not working when click to previewIcon - Antd - reactjs

According to the document here it says callback function onPreview will be executed when file link or preview icon is clicked. But only the file link works for me. I can't figure out what is the problem here.
<Upload
beforeUpload={() => false}
listType="picture"
maxCount={1}
accept="video/mp4"
onPreview={() => console.log("HELLO")}
>
<Button readOnly={someLogic} icon={<UploadOutlined />}>
{t("admin_entity.add_video")}
</Button>
</Upload>

As i checked, the issue is come from file's thumbnail.
It works with with an image ( which can generate a thumbnail in list ).
Maybe you can try to override the thumbnail with some event listener on it, just a workaround solution :)

I used iconRender function to solve this problem
iconRender={(originNode) => (
<PlaySquareTwoTone onClick={() => console.log("HELLO")} />
)}

Related

Ant design message doesnot work on onclick

So I am trying to display a message when a button is clicked but what it does is that when the page is loaded it displays message boxes (which should not happen) but it doesn't work on onclick I have attached the screenshots to my code and views.
You need to pass your function to the onClick parameter, not invoke it.
<Button type="primary" shape="round" onClick={() => info()} />
or
<Button type="primary" shape="round" onClick={info} />

Field Array in React using formik

I wanted to follow like a todo list. Something just like in the picture below.
Right now, the problem with my code is that, its working differently.
I wanted only one input that renders a list of divs instead of input fields.
Exactly just like in the picture below:
Pls check my codesandbox here
CLICK HERE
<FieldArray
name="todos"
render={(arrayHelpers) => (
<div>
{formik.values.todos.map((friend, index) => (
<div key={index} style={{ display: "flex", gap: "1rem" }}>
<input
name={`todos[${index}].name`}
value={formik.values.todos[index].name}
onChange={formik.handleChange}
/>
<button
disabled={formik.values.todos?.length === 1}
type="button"
onClick={() => arrayHelpers.remove(index)}
className="deleteButton"
>
Remove
</button>
</div>
))}
<button
type="button"
onClick={() => arrayHelpers.push({ name: "" })}
>
Add
</button>
</div>
)}
/>
Here is a very simple and rude approach - I used Formik my project some time ago and I'm pretty sure it's not perfect but this is exactly what you need.
So some details.
do not render input for every item in your list, you need only render it's value and element with delete handler
you need only one controlled input and it's value is used for name field in your todos. State is cleaned when you click Add button.
you need to render your element only if formik.values.todos.lenght > 0
you need to disable Delete button when formik.values.todos.lenght === 1
Add button should be disabled when newValue.lenght === 0
Piece a cake, right?

How to increase Antd Collapse icon size and change it if collapse is expanded

I need to do two things:
Need to increase default icon arrow size
Need to change icon to a different one when the panel is expanded.
I managed to do that this way:
<Collapse
expandIconPosition='right'
className='collapse-container'
// this works fine
expandIcon={({isActive}) => isActive
? <img src={closeCollapseIcon} />
: <img src={openCollapseIcon} />}
>
<Panel header='Question...' key='3'>
<p className='help-panel-text'>Some text</p>
</Panel>
</Collapse>
My question is:
Is there a way to do the same but in a more elegant way? My solution seems to be too straightforward.
You dont need to render two img tags, you can achieve the same thing with one tag. A more appropriate way would be using the Icon component provided by ant design
expandIcon={({ isActive }) => (
<Icon
component={isActive ? closeCollapseIcon : openCollapseIcon}
width="2em"
height="2em"
/>
)}

React Material IconButton send object to handle function

I'm coding a list on ReactJS using https://v3.material-ui.com/ . In the list I place a delete button:
<IconButton
color="warning"
className={classes.button}
onClick={this.handleDelete}
value={item}
aria-label={intl.formatMessage({
id: "Worksheet.delete",
defaultMessage: "Delete",
})}
>
<Delete />
</IconButton>
value={item} has the object I want to get to the handleDelete function. Now I'm trying to find out how to retrieve the object. I've tried e.currentTarget, e.target. It's not in there.
Am I doing it the right way?
I found the answer: onClick={() => this.handleDelete(item)}.
This will send the whole object to the handle function

In Next.js, how to scroll to top of window after setting search value on a search bar?

Imagine I have a button somewhere. When clicked, the text on it, now goes to my search bar. How do I make the window scroll to the search bar too after the value is set in the Input element shown below?
<Flex
flexDirection="column"
justifyContent="center"
alignItems="center"
maxWidth="90%"
mt={4}
>
{!filteredBlogPosts.length && 'No posts found.'}
{filteredBlogPosts.map((frontMatter) => (
<>
<BlogPost
key={frontMatter.title + frontMatter.lastPublishedOn}
handleSearch={(anyKey) => setSearchValue(anyKey)}
// Insert your code here, how to scroll after setting the key to search?
{...frontMatter}
/>
</>
))}
</Flex>
And, here is the <Input> field
<Input
aria-label="Search"
borderColor="blue.500"
onChange={(e) => setSearchValue(e.target.value)}
placeholder="Search"
value={searchValue}
//or should I do scroll here? How?
autoFocus
onFocus={e => e.currentTarget.select()}
/>
Is this something easy to do? Please present code examples if possible.
Thanks.
If anyone faces this issue in the future, I solved it using this simple function.
const scrollSearch = myKey => {
window.scrollTo(0, 0);
frontMatter.handleSearch(myKey)
};
And passed the scrollSearch function in button onClick.

Resources