Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to get value from switch #258

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Fixed
- `Switch` - not passing correct value.

## v6.0.6 - 2021-10-08

Expand Down
24 changes: 13 additions & 11 deletions packages/icon/src/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ const Icon = ({ name, style, className, ariaLabel, onClick, src, qa }: Props) =>
/**
* Inject SVG icons from core branding into page
*/
const fetchAntwerpIcons = async function() {
const fetchAntwerpIcons = function() {
if (!fetch) return;

try {
const xlinkHref = 'https://cdn.antwerpen.be/core_branding_scss/5.0.0/assets/images/ai.svg';
const response = await fetch(xlinkHref);
const svgText = await response.text();

const svgWrapper = document.createElement('svg');

svgWrapper.id = 'aiSvg';
svgWrapper.innerHTML = svgText;
if(!document.getElementById('aiSvg')) {
document.body.appendChild(svgWrapper);
}
const response = fetch(xlinkHref)
.then((response) => response.text())
.then((svgText) => {
const svgWrapper = document.createElement('svg');

svgWrapper.id = 'aiSvg';
svgWrapper.innerHTML = svgText;
if(!document.getElementById('aiSvg')) {
document.body.appendChild(svgWrapper);
}
});
} catch(err) {
throw new Error(err);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/switch/Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- `onClick` will pass the element that was clicked
- `onChecked` will pass `true` of `false` based on if the checkbox is checked

```
<Switch
label={"Declared and approved"}
Expand All @@ -7,5 +10,6 @@
required={true}
disabled={false}
checked={true}
onClick={(value) => console.log('select value is:', value)} />
onClick={(value) => console.log('select value is:', value)}
onChecked={(value) => console.log('checked value is:', value)} />
```
5 changes: 5 additions & 0 deletions packages/switch/src/Switch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IProps {
labelTrue: string;
labelFalse: string;
onClick?: (event) => void;
onChecked?: (checked) => void;
disabled?: boolean;
ariaLabel?: string;
qa?: string;
Expand All @@ -34,6 +35,10 @@ class Switch extends Component<IProps> {
if (this.props.onClick && (typeof this.props.onClick === 'function')) {
this.props.onClick(e);
}

if (this.props.onChecked && (typeof this.props.onChecked === 'function')) {
this.props.onChecked(!this.state.checked);
}
}

render() {
Expand Down