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

fix(action-sheet): optimize ActionSheet component #1541

Open
wants to merge 2 commits into
base: develop
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: 1 addition & 1 deletion src/action-sheet/demos/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const badgeData = {
},
],
};
const handleSelected = (selected: ActionSheetItem, selectedIndex: number) => {
const handleSelected = (selected: ActionSheetItem | string, selectedIndex: number) => {
console.log(selected, selectedIndex);
ActionSheet.close();
};
Expand Down
12 changes: 5 additions & 7 deletions src/action-sheet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ function create(props: Partial<TdActionSheetProps>): DefineComponent<TdActionShe
const root = document.createElement('div');
document.body.appendChild(root);

const visible = ref(false);
const propsObject = {
visible,
defaultVisible: true,
...props,
};

Expand All @@ -39,14 +38,11 @@ function create(props: Partial<TdActionSheetProps>): DefineComponent<TdActionShe
};
app = createApp(instance, { ...propsObject });
app.mount(root);
nextTick(() => {
visible.value = true;
});
return instance;
}

function ActionSheet(props: Partial<TdActionSheetProps>) {
create(props);
return create(props);
}

ActionSheet.close = (trigger: any) => {
Expand All @@ -56,7 +52,7 @@ ActionSheet.close = (trigger: any) => {
};

ActionSheet.show = (props: Partial<TdActionSheetProps>) => {
create(props);
return create(props);
};

ActionSheet.install = (app: App, name = '') => {
Expand All @@ -66,6 +62,8 @@ ActionSheet.install = (app: App, name = '') => {
type ActionSheetApi = {
/** 关闭ActionSheet */
close: () => void;
/** 打开ActionSheet */
show: (props: Partial<TdActionSheetProps>) => DefineComponent<TdActionSheetProps>;
};

export const _ActionSheet: WithInstallType<typeof ActionSheetVue> & ActionSheetApi = ActionSheet as any;
Expand Down
Loading