Giter Site home page Giter Site logo

Comments (5)

enuchi avatar enuchi commented on July 29, 2024

Hmm that's strange -- there should be no difference. I was just able to trigger focus in the Sheets demo app I included, but I needed to change the line below in the server code to use showModelessDialog() instead of showModalDialog.

SpreadsheetApp.getUi().showModalDialog(html, 'Sheet Editor');

Modeless dialogs let you interact with the main page behind it: https://developers.google.com/apps-script/reference/base/ui#showModelessDialog(Object,String)

Also, the official documentation for script.host.editor.focus specifies only "Google Docs, Sheets, or Forms," and not Slides. Assume it would work the same way in Slides though if you say it has worked for you.
https://developers.google.com/apps-script/guides/html/reference/host#index.html_1

from react-google-apps-script.

poorawaste avatar poorawaste commented on July 29, 2024

Thanks for the quick response. However that isn’t my issue. My bad, I should've been clearer in my question. Here’s a slightly detailed explanation:
I’ve built a sidebar addon with your template. Overall it’s working great. I have a “left align” button that runs a server side command to align all selected items to the left. Also working great. But if I were to hit “command z” it doesn’t undo the alignment. That’s because the last place I clicked was in the sidebar addon on the button. I am forced to click back in the document to execute an undo. I resolved that in my previous script written in Google Apps Script by running google.script.host.editor.focus(). It would programmatically move the focus back to the Slides document.
That is where the issue is. I can’t seem to find a way to do that in this template.
I hope that clarifies the issue.
Thank you again.

from react-google-apps-script.

enuchi avatar enuchi commented on July 29, 2024

Have you tried adding the focus command in your button onClick handler? I would do something like:

<button
  onClick={() => {
     serverFunctions.runSomeServerFunction()
        .then(() => google.script.host.editor.focus());
   }}
/>

from react-google-apps-script.

poorawaste avatar poorawaste commented on July 29, 2024

It worked!
It's weird because I had tried that before and it didn't work. I also tried async/await and it hadn't. After further testing I realized that google.script.host.editor.focus() only works after deploying the files. Not during the local development using the npm run start command.
Thank you!

from react-google-apps-script.

enuchi avatar enuchi commented on July 29, 2024

Ah, yes that makes sense! Should have mentioned it won't work in local development @poorawaste .

The repos that support the local development environment could actually be modified to support google.script.host.editor.focus(), but it would be a bit of work and don't think it's worth the trouble since they're probably not used much. The only google client API that's been set up to work in local development is google.script.run.

See https://github.com/enuchi/gas-client and https://github.com/enuchi/Google-Apps-Script-Webpack-Dev-Server if you're interested in digging in to the internals.

from react-google-apps-script.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.