Skip to content

Commit

Permalink
feat(radio): add styles for onFocusByKeyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Enlcxx committed Dec 28, 2018
1 parent 3f55cf0 commit bc47a5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/radio/radio.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<label #_labelContainer [attr.for]="inputId" [className]="classes.label">
<input
<input #_input
[className]="coreStyles.classes.visuallyHidden"
[id]="inputId"
[checked]="checked"
Expand Down
34 changes: 30 additions & 4 deletions src/lib/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
FormsModule,
} from '@angular/forms';
import { CommonModule } from '@angular/common';
import { LyCommonModule, LyTheme2, LyCoreStyles, toBoolean, mixinDisableRipple, ThemeVariables } from '@alyle/ui';
import { LyCommonModule, LyTheme2, LyCoreStyles, toBoolean, mixinDisableRipple, ThemeVariables, LyFocusState, LY_COMMON_STYLES } from '@alyle/ui';

const STYLE_PRIORITY = -2;
const DEFAULT_DISABLE_RIPPLE = false;
Expand Down Expand Up @@ -57,7 +57,13 @@ export const STYLES = (theme: ThemeVariables) => ({
transform: 'scale(0.8)'
}
}
}
},
'&{onFocusByKeyboard} {container}::after': {
boxShadow: '0 0 0 12px',
background: 'currentColor',
opacity: .13,
borderRadius: '50%',
},
},
label: {
cursor: 'pointer',
Expand All @@ -82,6 +88,13 @@ export const STYLES = (theme: ThemeVariables) => ({
width: '1em',
height: '1em'
},
'&::after': {
content: `''`,
...LY_COMMON_STYLES.fill,
width: '16px',
height: '16px',
margin: 'auto'
},
'div:nth-child(2)': {
background: 'currentColor',
transform: 'scale(0)'
Expand All @@ -98,7 +111,8 @@ export const STYLES = (theme: ThemeVariables) => ({
transition: 'transform cubic-bezier(.1, 1, 0.5, 1)',
transitionDuration: '250ms'
}
}
},
onFocusByKeyboard: null
});

@Component({
Expand Down Expand Up @@ -266,6 +280,7 @@ export class LyRadio extends LyRadioMixinBase implements OnInit, AfterViewInit,
private _color: string;
private _colorClass: string;
private _animClass: string;
@ViewChild('_input') _input: ElementRef;
@ViewChild('_radioContainer') private _radioContainer: ElementRef;
@ViewChild('_labelContainer') _labelContainer: ElementRef;
@Output() change = new EventEmitter<boolean>();
Expand Down Expand Up @@ -336,7 +351,8 @@ export class LyRadio extends LyRadioMixinBase implements OnInit, AfterViewInit,
theme: LyTheme2,
private changeDetectorRef: ChangeDetectorRef,
ngZone: NgZone,
public coreStyles: LyCoreStyles
public coreStyles: LyCoreStyles,
private _focusState: LyFocusState
) {
super(theme, ngZone);
this._triggerElement = this._elementRef;
Expand Down Expand Up @@ -365,6 +381,16 @@ export class LyRadio extends LyRadioMixinBase implements OnInit, AfterViewInit,
if (this.disableRipple == null) {
this.disableRipple = DEFAULT_DISABLE_RIPPLE;
}
const focusState = this._focusState.listen(this._input, this._elementRef);
if (focusState) {
focusState.subscribe((event) => {
if (event === 'keyboard') {
this._renderer.addClass(this._elementRef.nativeElement, this.classes.onFocusByKeyboard);
} else if (event == null) {
this._renderer.removeClass(this._elementRef.nativeElement, this.classes.onFocusByKeyboard);
}
});
}
}

_markForCheck() {
Expand Down

0 comments on commit bc47a5e

Please sign in to comment.