Skip to content

Commit 0f1bfc8

Browse files
committed
fix set value using form control directive
1 parent 902040f commit 0f1bfc8

File tree

7 files changed

+22
-14
lines changed

7 files changed

+22
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [Unreleased]
4+
## [0.2.1] - 2021-11-15
55
### Added
6-
- Changelog
6+
- Fixed issue setting default value when using Reactive Forms
7+
- Fixed issue with margin in toggle
8+
- Addes Changelog
79

810
## [0.2.0] - 2021-07-25
911
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ng-toggle-button",
33
"description": "A toggle button component",
44
"author": "vicmans",
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"homepage": "https://github.com/vicmans/ng-toggle-button#readme",
77
"repository": {
88
"type": "git",

projects/demo/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class AppComponent {
4040
myForm: FormGroup;
4141
constructor() {
4242
this.myForm = new FormGroup({
43-
'show': new FormControl()
43+
'show': new FormControl(false)
4444
})
4545
}
4646

projects/demo/src/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
<meta property="og:title" content="Toggle Button Demo">
1414
<meta property="og:type" content="article">
15-
<meta property="og:url" content="https://vicmans.com/">
16-
<meta property="og:image" content="https://vicmans.com/toggle.png">
15+
<meta property="og:url" content="http://vicmans.com/">
16+
<meta property="og:image" content="http://vicmans.com/toggle.png">
1717
<meta property="og:description" content="This is a toggle switch button component, you can use this components in your Angular projects">
1818
<meta property="og:site_name" content="Vicmans's demos">
1919

@@ -22,7 +22,7 @@
2222
<meta name="twitter:title" content="Toggle Button Demo">
2323
<meta name="twitter:description" content="This is a toggle switch button component, you can use this components in your Angular projects">
2424
<meta name="twitter:creator" content="@vmsanchz">
25-
<meta name="twitter:image" content="https://vicmans.com/toggle.png">
25+
<meta name="twitter:image" content="http://vicmans.com/toggle.png">
2626

2727
<link rel="icon" type="image/x-icon" href="favicon.ico">
2828
</head>

projects/ng-toggle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-toggle-button",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Angular toggle button switch",
55
"author": "vicmans",
66
"license": "MIT",

projects/ng-toggle/src/lib/ng-toggle.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
label {
2+
margin: 0;
3+
padding: 0;
4+
border: 0;
5+
font-size: 100%;
6+
font: inherit;
7+
vertical-align: baseline;
8+
}
19
.ng-toggle-switch {
210
display: inline-block;
311
position: relative;

projects/ng-toggle/src/lib/ng-toggle.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor {
6161
}
6262

6363
writeValue(value: any): void {
64-
if (value) {
65-
this.value = value == true ? this.values.checked : this.values.unchecked;
66-
} else {
67-
this.value = this.values.unchecked;
68-
}
64+
this.value = value;
65+
this.setToogle();
6966
}
7067
registerOnChange(fn: any): void {
7168
this.onChange = fn;
@@ -96,7 +93,8 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor {
9693
}
9794
}
9895
get buttonRadius () {
99-
return this.height - this.margin * 2;
96+
const radius = this.height - this.margin * 2;
97+
return radius > 0 ? radius : 0;
10098
}
10199
get distance () {
102100
return px(this.width - this.height + this.margin)

0 commit comments

Comments
 (0)