Comments (5)
Hello!
I am unable to reproduce this issue. with the following code, it closes after 1 second
(tested in a create vite app with 0.40.1)
function SnackbarSample() {
const [message, setMessage] = useState({ open: false, text: '' })
return (
<>
<Button
onClick={() => setMessage({ open: true, text: 'test' })}
>
Show snackbar for 1 second
</Button>
<Snackbar
open={message.open}
onClose={() => setMessage({ open: false, text: '' })}
autoHideDuration={1000}
>
{message.text}
</Snackbar>
</>
)
}
So there must be some missing piece to this puzzle, with how it is implemented perhaps?
from design-system.
I found the missing piece to this puzzle, it's an interval.
In the below example the Snackbar does not autohide at all when the button is clicked.
import { useEffect, useState } from 'react'
import {
Button,
Snackbar,
} from '@equinor/eds-core-react';
import './App.css'
function App() {
const [message, setMessage] = useState({ open: false, text: '' });
const [data, setData] = useState(0);
const handleClick = () => {
setMessage({ open: true, text: 'Hello, World!' });
};
useEffect(() => {
const interval = setInterval(() => {
setData(data => data + 1);
}, 1000);
return () => clearInterval(interval);
}, []);
return (
<>
<div>
<Button onClick={() => handleClick()}>
Show Snackbar + {data}
</Button>
<Snackbar
open={message.open}
onClose={() => setMessage({ open: false, text: '' })}
autoHideDuration={2000}
>
{message.text}
</Snackbar>
</div>
</>
)
}
export default App
from design-system.
I found another way to trigger the issue using a second button.
Steps:
-press first button (Snackbar will show)
-press second button every second
Result:
As long as you (continuously) press the second button the Snackbar will stay open
It looks like each render resets the Snackbar timeout
Code:
import { useState } from 'react'
import {
Button,
Snackbar,
} from '@equinor/eds-core-react';
import './App.css'
function App() {
const [message, setMessage] = useState({ open: false, text: '' });
const [data, setData] = useState(0);
const handleClick = () => {
setMessage({ open: true, text: 'Hello, World!' });
};
const handleDataClick = () => {
setData(data + 1);
};
return (
<>
<div>
<Button onClick={() => handleClick()}>
Show Snackbar
</Button>
<Button style={{marginLeft: '10px'}} onClick={() => handleDataClick()}>
Data + {data}
</Button>
</div>
<div>
<Snackbar
open={message.open}
onClose={() => setMessage({ open: false, text: '' })}
autoHideDuration={2000}
>
{message.text}
</Snackbar>
</div>
</>
)
}
export default App
from design-system.
Aha... sounds like something needs to be memiozed properly
from design-system.
Looks like removing the onClose function from the useEffect dependency array fixed it. I'll make a patch release with this fix 👍
from design-system.
Related Issues (20)
- Add access to current table state in eds-data-grid
- Export defaultColumn options from data grid
- Button.Toggle: remove type check to allow wrapped Buttons as children
- 🔖Release [email protected]
- 🔖Release [email protected]
- Data pickers show random dateformats HOT 4
- ✨Implement popover on Popover
- Input mask option for the Input component HOT 2
- 🔥 Autocomplete: remove deprecated disablePortal prop
- 🔖 release [email protected]
- Hovering over a cell in our AGGrid in UDD causes an error HOT 1
- Autocomplete single select highlight will not reflect programatically set `selectedOptions` HOT 1
- 🐛InputProps type is missing native props
- 🔖Release [email protected]
- Scrim -> Sidesheet -> Dialog hides scrollbar, and doesnt give it back after closing all of them HOT 2
- Feature request: Clickable components should take a promise, and be disabled while running HOT 2
- 🔖Release [email protected]
- Add description or add placement option for meta and add possibility for font size 16
- Allow `Dialog` to have a blurred background HOT 1
- 🔖Release [email protected] and [email protected] HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from design-system.