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

feat(component): allow delegatesFocus on the component decorator #1190

Closed
wants to merge 11 commits into from
17 changes: 13 additions & 4 deletions src/compiler/transpile/datacollection/component-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getDeclarationParameters, isDecoratorNamed, serializeSymbol } from './u
import { getStylesMeta } from './styles-meta';
import ts from 'typescript';


export function getComponentDecoratorMeta(diagnostics: d.Diagnostic[], checker: ts.TypeChecker, node: ts.ClassDeclaration): d.ComponentMeta | undefined {
if (!node.decorators) {
return undefined;
Expand Down Expand Up @@ -50,11 +49,17 @@ It will be removed in future versions. Please use the "hostData()" method instea
jsdoc: serializeSymbol(checker, symbol)
};

// normalizeEncapsulation
cmpMeta.encapsulationMeta =
componentOptions.shadow ? ENCAPSULATION.ShadowDom :
// shadow dom options
if(componentOptions.shadow){
cmpMeta.encapsulationMeta = ENCAPSULATION.ShadowDom
if(isShadowDomOptions(componentOptions.shadow)) {
MrAntix marked this conversation as resolved.
Show resolved Hide resolved
cmpMeta.shadowRootOptions = componentOptions.shadow;
}
} else {
cmpMeta.encapsulationMeta =
componentOptions.scoped ? ENCAPSULATION.ScopedCss :
ENCAPSULATION.NoEncapsulation;
}

// assetsDir: './somedir'
if (componentOptions.assetsDir) {
Expand Down Expand Up @@ -107,3 +112,7 @@ function getHostMeta(diagnostics: d.Diagnostic[], hostData: d.HostMeta) {

return hostData;
}

function isShadowDomOptions(o: any): o is d.ShadowDomOptions {
return o && typeof(o) === 'object';
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ describe('component decorator', () => {
});
});

it('shadow encapsulation with options', () => {
let response;
const sourceFilePath = path.resolve(__dirname, './fixtures/component-shadow-w-options');
gatherMetadata(sourceFilePath, (checker, classNode) => {
response = getComponentDecoratorMeta([], checker, classNode);
});

expect(response).toEqual({
tagNameMeta: 'ion-action-sheet',
hostMeta: {},
stylesMeta: {},
encapsulationMeta: ENCAPSULATION.ShadowDom,
shadowRootOptions: { delegatesFocus: true },
jsdoc: {
documentation: '',
name: 'ActionSheet',
tags: [],
type: 'typeof ActionSheet'
},
assetsDirsMeta: [],
dependencies: []
});
});

it('scoped encapsulation', () => {
let response;
const sourceFilePath = path.resolve(__dirname, './fixtures/component-scoped');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '../../../../../index';

@Component({
tag: 'ion-action-sheet',
shadow: { delegatesFocus: true }
})
class ActionSheet {
}
2 changes: 1 addition & 1 deletion src/core/host-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function initHostSnapshot(domApi: d.DomApi, cmpMeta: d.ComponentMeta, hos
// this component is using shadow dom
// and this browser supports shadow dom
// add the read-only property "shadowRoot" to the host element
domApi.$attachShadow(hostElm, { mode: 'open' });
domApi.$attachShadow(hostElm, { mode: 'open', ...cmpMeta.shadowRootOptions });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/declarations/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ComponentMeta {
listenersMeta?: ListenMeta[];
hostMeta?: HostMeta;
encapsulationMeta?: number;
shadowRootOptions?: Readonly<d.ShadowDomOptions>;
assetsDirsMeta?: AssetsMeta[];
componentConstructor?: ComponentConstructor;
componentClass?: string;
Expand Down
6 changes: 4 additions & 2 deletions src/declarations/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export interface ComponentOptions {
styleUrls?: string[] | d.ModeStyles;
styles?: string;
scoped?: boolean;
shadow?: boolean;
shadow?: boolean | ShadowDomOptions;
host?: d.HostMeta;
assetsDir?: string;
assetsDirs?: string[];
}

export interface ShadowDomOptions {
delegatesFocus?: boolean;
}

export interface PropDecorator {
(opts?: PropOptions): PropertyDecorator;
Expand Down