Skip to content

Commit

Permalink
Refactor condition to include a hover match
Browse files Browse the repository at this point in the history
  • Loading branch information
JamiuShaibu committed Feb 15, 2025
1 parent 11aca1d commit fc43bee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-language-selector-lite",
"version": "1.2.8",
"version": "1.3.1",
"description": "A lightweight language selector for React applications",
"main": "dist/LanguageSelector.js",
"types": "src/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/LanguageSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ const LanguageSelector = ({
useEffect(() => {
const event = lowerCase(render);
const buttonElement = activeButtonRef.current;

// Detect if the device supports hover
const canHover = window.matchMedia("(hover: hover)").matches;
// Detect if the device supports touch
const isTouchDevice =
"ontouchstart" in window || navigator.maxTouchPoints > 0;

const renderEvent =
event === "onhover" && isTouchDevice ? "onclick" : event;
event === "onhover" && (isTouchDevice || !canHover) ? "onclick" : event;

const handleMouseEnter = () => setIsOpenSelector(true);
const handleMouseLeave = (e) => {
Expand Down

0 comments on commit fc43bee

Please sign in to comment.