Convert ContextualMenuItem to css-in-js
Bug Report Describe the issue: A few issues with the custom styles for IContextualMenuItem
IContextualMenuItem accepts a style: React.CSSProperties but its seems like its never used in code, also the method provided for customStyling of IContextualMenuItem
getItemClassNames?: (theme: ITheme,
disabled: boolean,
expanded: boolean,
checked: boolean,
isAnchorLink: boolean,
knownIcon: boolean,
itemClassName?: string,
dividerClassName?: string,
iconClassName?: string,
subMenuClassName?: string) => IMenuItemClassNames;
is not supportive either, to implement this method in consuming code your code needs to know lot about office-ui-fabric-code.
Problems with implementing getItemClassNames in consuming repo.
IMenuItemClassNamestype is required to implement this method which is non importable from package.- To implement this method you need to copy paste
getContextualMenuClassNamesinContextualMenu.classNames.tsand make changes to desirable properties.
Suggestion:
style property should be of type IContextualMenuStyles which should be merged with default styles.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Fabric React!
stay alive
Any update on this?
@d-khoury Currently in progress actually so there should be a PR in the next week if all goes smoothly.
@oengusmacinog Thank you, can you update this thread when the PR is completed?
@d-khoury absolutely, the PR will autoclose this issues actually
@oengusmacinog Is there a way I can get automatically notified when the issue is resolved?
@d-khoury it looks like @oengusmacinog didn't actually fix this; the PR #5461 has an explicit comment saying
Note only ContextualMenu has been converted, not ContextualMenuItem due to time constraints.
@oengusmacinog what is your plan for finishing this? @cliffkoh had a very astute comment in the PR...
Should we really check in stuff halfway? It makes it really confusing as to the state and usability of the API (personally, I don't even check it in in 2 parts because of this problem).
I won't be able to do the ContextualMenuItem. @micahgodbolt do you know who might be able to pick this up?
I can make sure it gets done. I don't know if I'll have the time to dive into it right now.
Setting as pri 1 because the component is in a halfway state atm, which is bad :(
@KevinTCoughlin said he could dive into this. There's several questions about implementation though. As a child we could use subComponentStyles, or the contextualMenuItemAs, OR pass a styles prop through each item.....and the solution is probably a combination of the 3
I was going to take a look at TextField and any other components that support a similar rendering paradigm and figure it out. Pointers welcome.. been some time since I looked at this, but I think I can figure it out.
scenarios to support: Single styles function to style entire contextualMenu Ability to apply custom styles per item Ability to style differently based on what type of item it is (header, divider, regular etc)
Work
- [x] Get working example w/
ContextualMenuItemstyled via item props (styles, style, className, classNames) - [x] Get working example w/
ContextualMenustyled via props (styles, getMenuClassNames) - [x] Apply deprecation warnings where necessary
- [x] Verify public API same i.e. no breaking changes
Test Scenarios
- [x] Single styles function to style entire contextualMenu
- [x] Ability to apply custom styles per item
- [x] Ability to style differently based on what type of item it is (header, divider, regular etc)
I've raised a PR, but am going thru the various modes of styling once more to make sure we're covered prior to merge. Getting close..
Thanks for your patience and for the initial report @essar123. I've converted ContextualMenu to use getStyles for itself as well as the ContextualMenuItem(s). I've also deprecated the classNames approach and related fields / types.
This comment goes over the various ways to use getStyles https://github.com/OfficeDev/office-ui-fabric-react/pull/6094#issuecomment-417423698.
For styling various aspects of the menu, you can provide a styles? prop as part of menuProps:
const getMenuStyles = (): Partial<IContextualMenuStyles> => {
return {
root: {
background: 'blue'
}
};
};
...
menuProps={{
shouldFocusOnMount: true,
styles: getMenuStyles,
...
For styling individual items within a menu, you can provide a styles? within itemProps? per IContextualMenuItem definition:
const getMenuItemStyles = (): Partial<IContextualMenuItemStyles> => {
return {
linkContent: {
color: 'red'
}
};
};
...
menuProps={{
shouldFocusOnMount: true,
items: [
{
key: 'newItem',
text: 'New',
onClick: () => console.log('New clicked'),
itemProps: { styles: getMenuItemStyles }
},
...
More information about the styles prop can be find in our Wiki