spModal autofocus

cnough
Tera Contributor

Is there a way to change where spModal autofocuses?

When I open spModal, it always focuses on the X button.

I would like to focus on the modal title when it opens.

3 REPLIES 3

Barrilito van D
Kilo Guru

Hi, no answer from me to solve this. But I was happy to see your question. Was struggeling with this months ago, and I never post a question or ask for help. But yes I DO want to still fix it 🙂 So hope someone will have the answer and I will be in the loop for it as well. I tried setting focus on other things, but never got it to work. For something OOTB I found this very annoying to work like this as it is a visual thing that realy looks not nice in the page. Hope someone can help you fix it. Good luck!

Bob Loblaw
Mega Guru

After reading the accepted solution on this post, I tried adding "focus: true" on the button I wanted initial focus on (and no longer on the 'X') and it worked, resulting in this:

 

 

spModal.open({
    title: 'Modal Title',
    message: 'Modal content goes here',
    buttons: [
        {label:'Cancel', cancel: true, focus: true}, //<<-- see the "focus: true" here
        {label:'OK', primary: true}
    ]
})

 

 

Bob Loblaw
Mega Guru

@cnough please mark as answered (if think so) so others can see how to solve this - thanks!