-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: MenuItem, MenuGroup and SubMenu support ref (#683)
* feat: MenuItem, MenuGroup and SubMenu support ref * docs: add demo * docs: add ref * test: add case * docs: fix demo
- Loading branch information
Showing
8 changed files
with
485 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## items-ref | ||
|
||
<code src="../examples/items-ref.tsx"></code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint no-console:0 */ | ||
|
||
import React, { useRef } from 'react'; | ||
import '../../assets/index.less'; | ||
import Menu from '../../src'; | ||
|
||
export default () => { | ||
const ref1 = useRef(); | ||
const ref2 = useRef(); | ||
const ref3 = useRef(); | ||
const ref4 = useRef(); | ||
const ref5 = useRef(); | ||
const ref6 = useRef(); | ||
const ref7 = useRef(); | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={() => { | ||
console.log(ref1.current); | ||
console.log(ref2.current); | ||
console.log(ref3.current); | ||
console.log(ref4.current); | ||
console.log(ref5.current); | ||
console.log(ref6.current); | ||
console.log(ref7.current); | ||
}} | ||
> | ||
获取 Ref | ||
</button> | ||
<Menu | ||
items={[ | ||
{ | ||
// MenuItem | ||
label: 'Top Menu Item', | ||
key: 'top', | ||
ref: ref1, | ||
}, | ||
{ | ||
// MenuGroup | ||
type: 'group', | ||
label: 'Top Menu Group without children', | ||
ref: ref2, | ||
}, | ||
{ | ||
// MenuGroup | ||
type: 'group', | ||
label: 'Top Menu Group with children', | ||
ref: ref3, | ||
children: [ | ||
{ | ||
// MenuItem | ||
label: 'Menu Item 1', | ||
key: 'inner1', | ||
}, | ||
{ | ||
// Divider | ||
type: 'divider', | ||
}, | ||
{ | ||
// MenuItem | ||
label: 'Menu Item 2', | ||
key: 'inner2', | ||
ref: ref4, | ||
}, | ||
], | ||
}, | ||
{ | ||
// SubMenu | ||
label: 'SubMenu', | ||
key: 'sub1', | ||
ref: ref5, | ||
children: [ | ||
{ | ||
// MenuItem | ||
label: 'Menu Item 1-1', | ||
key: 'inner11', | ||
ref: ref6, | ||
}, | ||
|
||
{ | ||
// SubMenu | ||
label: 'SubMenu inner', | ||
key: 'sub1-1', | ||
ref: ref7, | ||
children: [ | ||
{ | ||
// MenuItem | ||
label: 'Menu Item 111', | ||
key: 'inner1-1-1', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.