mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
e810eab39f
commit
b7974827d2
786 files changed
+14567
-24066
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import React from "react";
|
||||
|
||||
// Helper for preventing default event action and performing custom callback
|
||||
// 1)
|
||||
// <form onSubmit={prevDefault(() => console.log('do some action'))}>
|
||||
// <input name="text"/>
|
||||
// <button type="submit">Action</button>
|
||||
// </form>
|
||||
// 2)
|
||||
// <a href="/some-page-url">
|
||||
// <span>Link text</span>
|
||||
// <Icon onClick={prevDefault(() => console.log('stay on the page and open dialog'))}/>
|
||||
// </a>
|
||||
|
||||
export function prevDefault<E extends React.SyntheticEvent | Event>(callback: (evt: E) => any) {
|
||||
return function (evt: E) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
return callback(evt);
|
||||
}
|
||||
}
|
||||
|
||||
export function stopPropagation(evt: Event | React.SyntheticEvent) {
|
||||
evt.stopPropagation();
|
||||
}
|
||||
Reference in new issue
Block a user