OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
683 stars 95 forks source link

Unable to Enable/Disable contextual Sub Menu Items #3422

Closed shekar233 closed 1 month ago

shekar233 commented 1 year ago

Enable/Disable Multiple Contextual Menu Items on right click

Provide required information needed to triage your issue

Your Environment

Expected behavior

I want to enable/disable the Sub-Menu Items based on the worksheet or a specific cell within a sheet. i.e. Right Click --> Contextual Menu --> Sub-Menu1 --> Sub-Menu2

I want to Enable/Disable the Sub-Menu1 or Sub-Menu 2 based on which worksheet the user is working on or based on a particular cell/cell range the user right clicks on.

Current behavior

Current office documentation doesn't mention anything on how contextual menus can be enabled/disabled.

The Office.ribbon.requestUpdate(input: RibbonUpdaterData) supports only disabling/enabling the buttons on the ribbon of a Contextual Tab.

Steps to reproduce

  1. Add the ExtenstionPoint tag with type as ContextMenu in the manifest file, and the following code ore similar.

    <ExtensionPoint xsi:type="ContextMenu">
                      <OfficeMenu id="ContextMenuCell">
                        <Control xsi:type="Menu" id="Menu">
                                            <Label resid="Dropdown.Label" />
                                            <Supertip>
                                                <Title resid="Dropdown.Label" />
                                                <Description resid="Dropdown.Tooltip" />
                                            </Supertip>
    
                                            <Items>
                                                <Item id="Menu.Item1">
                                                    <Label resid="Item1.Label"/>
                                                    <Supertip>
                                                        <Title resid="Item1.Label" />
                                                        <Description resid="Item1.Tooltip" />
                                                    </Supertip>
    
                                                <Action xsi:type="ExecuteFunction">
                                                    <FunctionName>SubMenu1</FunctionName>
                                                </Action>
                                           <Enabled>false</Enabled>
                                                </Item>
                                                <Item id="Menu.Item2">
                                                <Label resid="Item2.Label"/>
                                                <Supertip>
                                                    <Title resid="Item2.Label" />
                                                    <Description resid="Item2.Tooltip" />
                                                </Supertip>
    
                                           <Action xsi:type="ExecuteFunction">
                                                <FunctionName>SubMenu2</FunctionName>
                                            </Action>
                                            </Item>
    
                                            </Items>
                                        </Control>
                      </OfficeMenu>
                  </ExtensionPoint>
  2. Then add the following code in the action's assigned method
    async function SubMenu1(args) {
    console.log("SignOff 1 started");
    Office.ribbon.requestUpdate({
    tabs: [
        {
            id: 'ContextMenuCell',
            controls: [
                {
                    id: 'Menu.Item1',
                    enabled: true
                }
            ]
        }
    ]
    });
    args.completed();
    }
    Office.actions.associate("SubMenu1", SubMenu1);

Link to live example(s)




Provide additional details

When the above code is executed I get the following error

Uncaught (in promise) RichApi.Error: ControlIdNotFound
    at new n (excel-win32-16.01.js:25:257638)
    at i.processRequestExecutorResponseMessage (excel-win32-16.01.js:25:321804)
    at excel-win32-16.01.js:25:319867

Context

I want to enable/disable these submenus based on different business requirements i.e. based on worksheet or based on cell or cell range etc. As shown in the attached image, I want to enable/disable Sub-Menu 1 or Sub-Menu 2 based on the active worksheet or active cell.

A better explanation of my requirement is posted in the following stackoverfow link. Enable/Disable Contextual Sub Menu Items

Useful logs

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

ghost commented 1 year ago

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

ShivharakhYadav commented 1 year ago

I have the same issue with Contextual Menu Items

Rick-Kirkham commented 1 year ago

I'm trying to find who to assign this to.

trigurl commented 1 year ago

Hello, enable/disable is not supported on the right click context menu at the moment.

Shukla-Dev commented 5 months ago

Is this issue is FIxed ?

rgold5950 commented 2 months ago

Also experiencing this issue. Can you please recommend a workaround?

NataliaKravcheniaTR commented 1 month ago

I have the same issue with context menu button/items.

EsterBergen commented 1 month ago

Hi @NataliaKravcheniaTR . @rgold5950 , and @Shukla-Dev - Currently you can only enable/disable ribbon buttons and not sub menu items. This would be a new feature. Please make a feature request here Microsoft 365 Developer Platform Ideas Forum. Please add your request there. Feature requests on are considered when we go through our planning process. Thanks for highlighting this!

NataliaKravcheniaTR commented 1 month ago

@EsterBergen Could you update the documentation that this functionality is only available in ribbon? https://learn.microsoft.com/en-us/office/dev/add-ins/design/disable-add-in-commands

EsterBergen commented 1 month ago

Great point. @samantharamon Can you have a look?

samantharamon commented 1 month ago

Thanks for the suggestion, @NataliaKravcheniaTR. Changes to the article have been merged (see PR#4838). These updates will be published by the end of today.