• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terrestris / react-geo / 19139111788

06 Nov 2025 02:32PM UTC coverage: 67.481% (-0.3%) from 67.733%
19139111788

Pull #4442

github

web-flow
Merge 3fdbdcc03 into 73a2a0381
Pull Request #4442: fix: improve ToggleGroup integration and context detection for GeoLocationButton

672 of 1088 branches covered (61.76%)

Branch coverage included in aggregate %.

1 of 6 new or added lines in 1 file covered. (16.67%)

2 existing lines in 1 file now uncovered.

1235 of 1738 relevant lines covered (71.06%)

13.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.15
/src/Button/GeoLocationButton/GeoLocationButton.tsx
1
import React, {
2
  FC
3
} from 'react';
4

5
import {
6
  type GeoLocation,
7
  useGeoLocation
8
} from '@terrestris/react-util/dist/Hooks/useGeoLocation/useGeoLocation';
9

10
import { CSS_PREFIX } from '../../constants';
11
import ToggleButton, { ToggleButtonProps } from '../ToggleButton/ToggleButton';
12

13
interface OwnProps {
14
  trackingOptions?: PositionOptions;
15
  /**
16
   * Will be called if geolocation fails.
17
   */
18
  onError?: () => void;
19
  /**
20
   * Will be called when position changes. Receives an object with the properties
21
   * position, accuracy, heading and speed
22
   */
23
  onGeoLocationChange?: (geolocation: GeoLocation) => void;
24
  /**
25
   * Whether to show a map marker at the current position.
26
   */
27
  showMarker?: boolean;
28
  /**
29
   * Whether to follow the current position.
30
   */
31
  follow?: boolean;
32
  /**
33
   * Enable tracking of GeoLocations
34
   */
35
  enableTracking?: boolean;
36
  /**
37
   * Will be called when the button is toggled
38
   */
39
  onChange?: (pressed: boolean) => void;
40
}
41

42
export type GeoLocationButtonProps = OwnProps & Partial<ToggleButtonProps>;
43

44
export const GeoLocationButton: FC<GeoLocationButtonProps> = ({
1✔
45
  className,
46
  enableTracking = false,
2✔
47
  follow = false,
14✔
48
  onChange,
UNCOV
49
  onError = () => undefined,
✔
UNCOV
50
  onGeoLocationChange = () => undefined,
✔
51
  pressed,
52
  showMarker = true,
1✔
53
  trackingOptions,
54
  value,
55
  ...passThroughProps
56
}) => {
57

58
  useGeoLocation({
14✔
59
    active: !!pressed,
60
    enableTracking: pressed && enableTracking,
20✔
61
    follow,
62
    onError,
63
    onGeoLocationChange,
64
    showMarker,
65
    trackingOptions
66
  });
67

68
  const finalClassName = className
14!
69
    ? `${className} ${CSS_PREFIX}geolocationbutton`
70
    : `${CSS_PREFIX}geolocationbutton`;
71

72
  const handleToggleButtonChange = (evt: React.MouseEvent<HTMLButtonElement>, buttonValue?: string) => {
14✔
NEW
73
    if (onChange) {
×
NEW
74
      if (buttonValue !== undefined) {
×
75
        // ToggleGroup context
NEW
76
        (onChange as any)(evt, buttonValue);
×
77
      } else {
78
        // Standalone context
NEW
79
        const newPressed = buttonValue !== undefined || !pressed;
×
NEW
80
        onChange(newPressed);
×
81
      }
82
    }
83
  };
84

85
  return (
14✔
86
    <ToggleButton
87
      pressed={pressed}
88
      className={finalClassName}
89
      onChange={handleToggleButtonChange}
90
      value={value}
91
      {...passThroughProps}
92
    />
93
  );
94
};
95

96
export default GeoLocationButton;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc