Skip to content
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
8 changes: 8 additions & 0 deletions docs/demo/defaultCurrent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: defaultCurrent
nav:
title: DefaultCurrent
path: /defaultCurrent
---

<code src="../examples/defaultCurrent.tsx"></code>
53 changes: 53 additions & 0 deletions docs/examples/defaultCurrent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useRef, useState } from "react";
import Tour from '../../src/index';

export default () => {
const btn1Ref = useRef<HTMLButtonElement>(null);
const btn2Ref = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false)

return <div style={{ margin: 20 }}>
<div>
<button
className="ant-target"
ref={btn1Ref}
style={{ marginLeft: 100 }}
onClick={() => {
setOpen(true);
}}
>
button1
</button>
<button className="ant-target" ref={btn2Ref} style={{ marginLeft: 100 }}>
defaultOpen
</button>
</div>

<div style={{ height: 200 }} />

<Tour
defaultCurrent={1}
open={open}
onFinish={() => setOpen(false)}
onClose={() => setOpen(false)}
steps={[
{
title: '创建',
description: '创建一条数据',
target: () => btn1Ref.current,
mask: true,
},
{
title: '更新',
description: (
<div>
<span>更新一条数据</span>
<button>帮助文档</button>
</div>
),
target: () => btn2Ref.current,
},
]}
/>
</div>
}
2 changes: 1 addition & 1 deletion src/Tour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Tour: React.FC<TourProps> = props => {
useLayoutEffect(() => {
if (mergedOpen) {
if (!openRef.current) {
setMergedCurrent(0);
setMergedCurrent(defaultCurrent ?? 0);
}

setHasOpened(true);
Expand Down