Comments (8)
I'm not sure I see a problem with that. Besides, if I decide to add one now, it could break some people's codebase as the class name specified could already be targeted.
I think if you need one, you could just add it to the ClickAway listeners.
If there's something I'm missing, please let me know 🙏
from react-click-away-listener.
I don't think adding a class name to the component would be a breaking change. If you make it an optional prop and use the package classnames
you can still pass their class name to the component too. I think it is a pretty sane default for the component to have a class name though.
from react-click-away-listener.
Nah, something could go wrong with that, as I mentioned earlier that it could already be targeted. We don't have a metric to work with, and there's a slight chance a developer might have used that same class name just to style the div.
Besides, I don't buy the idea of adding the classnames
library just to solve a specific problem that could be solved in alternative ways.
One way I could think of right now is by using data attributes. We could add a data-click-away-listener
to the base. What do you think?
from react-click-away-listener.
It wouldn't have any adverse effects. The classnames library already solves that problem by purging duplicate class names as shown here by using a dedupe method.
Personally, the better option would be to not make it a div at all. You could have the functionality attached to the child by using React.cloneElement
. You would also cease to stuffing the DOM with additional elements that way. It doesn't really make sense to render something that is just checking if a Mouse or Touch event is outside of its child's bounds. It's not like you are going to style a ClickOutsideListener. It is a pure functionality component.
from react-click-away-listener.
One of the biggest issues by not doing cloneElement
is that all of the event listeners are hi-jacked by your click listener. If I am making a dropdown or modal component that has click or keydown React synthetic events that it has to listen to, they would need to be applied to your click listener and not the modal or dropdown component. This would be a major breaking change though. Which means you would have to bump the major version up.
from react-click-away-listener.
I definitely agree with you on using cloneElement instead 💪
from react-click-away-listener.
I just opened a PR for it here #28. You can review when you have the time.
from react-click-away-listener.
We can close this since we've released a new version that uses cloneElement.
from react-click-away-listener.
Related Issues (19)
- Wrap children around the element passed through props, defaults to div if no element is specified HOT 2
- Update README to list the available APIs
- Portal HOT 12
- Warning when used within a form HOT 3
- Doesn't trigger with right click HOT 2
- Click away listener not working the same on React 17 HOT 5
- Memory Leak HOT 4
- Click inside of div on react-icons icon calls OnClickAway HOT 5
- Add mouse event and touch event props for more flexibility HOT 1
- React 17 has Error: Function components cannot be given refs. Attempts to access this ref will fail. HOT 7
- Could not resolve dependency: npm ERR! peer react@"^17.0.2" from [email protected] HOT 1
- an error appear in console when you add touchEvent HOT 2
- v2.2.0 introduced a breaking change by dropping React 17 support HOT 2
- Let click-away event do not report if we click / focus the children of the element. HOT 2
- Click on iframe elements doesn't trigger listener HOT 3
- OnClickAway trigger when I switch browser tab HOT 4
- onClickAway should return the fired event HOT 1
- v1.1.0 does not appear to be passing Event HOT 3
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 react-click-away-listener.