Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
e2b1261c
Commit
e2b1261c
authored
Dec 29, 2017
by
ddcat1115
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fix step-form can't match any menu item
- fix click logo can't change menu open keys
parent
2bbef8d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
src/components/SiderMenu/SiderMenu.js
src/components/SiderMenu/SiderMenu.js
+16
-4
No files found.
src/components/SiderMenu/SiderMenu.js
View file @
e2b1261c
...
@@ -16,6 +16,13 @@ export default class SiderMenu extends PureComponent {
...
@@ -16,6 +16,13 @@ export default class SiderMenu extends PureComponent {
openKeys
:
this
.
getDefaultCollapsedSubMenus
(
props
),
openKeys
:
this
.
getDefaultCollapsedSubMenus
(
props
),
};
};
}
}
componentWillReceiveProps
(
nextProps
)
{
if
(
nextProps
.
location
.
pathname
!==
this
.
props
.
location
.
pathname
)
{
this
.
setState
({
openKeys
:
this
.
getDefaultCollapsedSubMenus
(
nextProps
),
});
}
}
getDefaultCollapsedSubMenus
(
props
)
{
getDefaultCollapsedSubMenus
(
props
)
{
const
{
location
:
{
pathname
}
}
=
props
||
this
.
props
;
const
{
location
:
{
pathname
}
}
=
props
||
this
.
props
;
const
snippets
=
pathname
.
split
(
'
/
'
).
slice
(
1
,
-
1
);
const
snippets
=
pathname
.
split
(
'
/
'
).
slice
(
1
,
-
1
);
...
@@ -46,7 +53,6 @@ export default class SiderMenu extends PureComponent {
...
@@ -46,7 +53,6 @@ export default class SiderMenu extends PureComponent {
}
}
getSelectedMenuKeys
=
(
path
)
=>
{
getSelectedMenuKeys
=
(
path
)
=>
{
const
flatMenuKeys
=
this
.
getFlatMenuKeys
(
this
.
menus
);
const
flatMenuKeys
=
this
.
getFlatMenuKeys
(
this
.
menus
);
if
(
flatMenuKeys
.
indexOf
(
path
.
replace
(
/^
\/
/
,
''
))
>
-
1
)
{
if
(
flatMenuKeys
.
indexOf
(
path
.
replace
(
/^
\/
/
,
''
))
>
-
1
)
{
return
[
path
.
replace
(
/^
\/
/
,
''
)];
return
[
path
.
replace
(
/^
\/
/
,
''
)];
}
}
...
@@ -56,7 +62,7 @@ export default class SiderMenu extends PureComponent {
...
@@ -56,7 +62,7 @@ export default class SiderMenu extends PureComponent {
return
flatMenuKeys
.
filter
((
item
)
=>
{
return
flatMenuKeys
.
filter
((
item
)
=>
{
const
itemRegExpStr
=
`^
${
item
.
replace
(
/:
[\w
-
]
+/g
,
'
[
\\
w-]+
'
)}
$`
;
const
itemRegExpStr
=
`^
${
item
.
replace
(
/:
[\w
-
]
+/g
,
'
[
\\
w-]+
'
)}
$`
;
const
itemRegExp
=
new
RegExp
(
itemRegExpStr
);
const
itemRegExp
=
new
RegExp
(
itemRegExpStr
);
return
itemRegExp
.
test
(
path
.
replace
(
/^
\/
/
,
''
));
return
itemRegExp
.
test
(
path
.
replace
(
/^
\/
/
,
''
)
.
replace
(
/
\/
$/
,
''
)
);
});
});
}
}
getNavMenuItems
(
menusData
)
{
getNavMenuItems
(
menusData
)
{
...
@@ -126,10 +132,16 @@ export default class SiderMenu extends PureComponent {
...
@@ -126,10 +132,16 @@ export default class SiderMenu extends PureComponent {
}
}
render
()
{
render
()
{
const
{
collapsed
,
location
:
{
pathname
},
onCollapse
}
=
this
.
props
;
const
{
collapsed
,
location
:
{
pathname
},
onCollapse
}
=
this
.
props
;
const
{
openKeys
}
=
this
.
state
;
// Don't show popup menu when it is been collapsed
// Don't show popup menu when it is been collapsed
const
menuProps
=
collapsed
?
{}
:
{
const
menuProps
=
collapsed
?
{}
:
{
openKeys
:
this
.
state
.
openKeys
,
openKeys
,
};
};
// if pathname can't match, use the nearest parent's key
let
selectedKeys
=
this
.
getSelectedMenuKeys
(
pathname
);
if
(
!
selectedKeys
.
length
)
{
selectedKeys
=
[
openKeys
[
openKeys
.
length
-
1
]];
}
return
(
return
(
<
Sider
<
Sider
trigger
=
{
null
}
trigger
=
{
null
}
...
@@ -151,7 +163,7 @@ export default class SiderMenu extends PureComponent {
...
@@ -151,7 +163,7 @@ export default class SiderMenu extends PureComponent {
mode
=
"
inline
"
mode
=
"
inline
"
{...
menuProps
}
{...
menuProps
}
onOpenChange
=
{
this
.
handleOpenChange
}
onOpenChange
=
{
this
.
handleOpenChange
}
selectedKeys
=
{
this
.
getSelectedMenuKeys
(
pathname
)
}
selectedKeys
=
{
selectedKeys
}
style
=
{{
padding
:
'
16px 0
'
,
width
:
'
100%
'
}}
style
=
{{
padding
:
'
16px 0
'
,
width
:
'
100%
'
}}
>
>
{
this
.
getNavMenuItems
(
this
.
menus
)}
{
this
.
getNavMenuItems
(
this
.
menus
)}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment