Comments (4)
I pulled down the project and added the below to checkbox-svg-map.jsx
. Note that I installed lodash to compare the id arrays. For some reason github is giving me a hard time pushing up my branch :/
componentDidUpdate({ selectedLocationIds: prevSelectedLocationIds }) {
if (!_.isEqual(prevSelectedLocationIds, this.props.selectedLocationIds)) {
const svgNode = ReactDOM.findDOMNode(this);
const selectedLocations = this.props.selectedLocationIds.map(
(locationId) => svgNode.getElementById(locationId)
);
this.setState({ selectedLocations });
}
}
from react-svg-map.
This component was built to handle internally the state of the selected locations (kinda like an uncontrolled component). I think making selectedLocationIds
update the internal state would break the "single source of truth" principle.
It was created to fit the needs of my project, so it's probably a mistake of the initial design 🙇♂️
A better solution might be to follow the same API as react-checkbox-group:
value
to pass the selected ids to the checkbox componentonChange
to updatevalue
in the parent component
Unfortunately I think this issue can only be fixed in the next major version (v3.0.0) because there will be breaking changes.
I don't know when I have time to implement it, so if you need a quick solution, I would recommend to create your own checkbox component around SVGMap
.
If you want to contribute, feel free to open a PR on the v3.0.0
branch!
from react-svg-map.
I am also looking into using such a feature using RadioSVGMap
but I can't get it to re-render and update the locationId.
@insivika were you able to accomplish this task?
from react-svg-map.
@arslanakhtar61
Since RadioSVGMap
handles internally the state of the selected location (like CheckboxSVGMap
), updating selectedLocationId
won't re-render the component (as written in the documentation).
The next major version (v3.0.0) may include this feature. Until then, I would recommend to implement your own radio component around SVGMap
.
from react-svg-map.
Related Issues (20)
- Custom style for each location HOT 1
- Map Labels HOT 6
- installs with the error "TypeError: Cannot read property 'viewBox' of undefined" HOT 3
- Is there any option to define default checked locations? HOT 4
- Breaks when supplying an invalid state id to selectedLocationIds HOT 1
- Disable click behaviour on Checkbox map HOT 1
- Is there anyway to zoom in on a particular path onClick? HOT 2
- Can we get onLocationClick to CheckboxSVGMap HOT 3
- Styling the map HOT 2
- how add terrain type HOT 2
- RadioSVGMap broken in React 17 HOT 5
- Based on condition i want to select the state HOT 1
- Custom the SVG map color by edit the CSS HOT 2
- selectedLocationIds not working on checkbox svg map
- Control path opacity HOT 1
- How to adjust / add className into each path for coloring HOT 1
- How to convert Gejson files to compatible svg format HOT 1
- Map markers HOT 3
- convert to functional components
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-svg-map.