Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to set default value in sp-picker

Explorer ,
Jul 28, 2025 Jul 28, 2025
Hello sir,
How can I set a default value for <sp-picker> in UXP ? It renders and works fine, but I need the picker to show a pre-selected value on load.

 

TOPICS
How to
171
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 02, 2025 Oct 02, 2025
LATEST

Hi @ashwin_0502,

 

Not sure if you've figured this one out - but trying to learn myself.

 

Can you set a default value in <sp-picker> by passing a value that matches one of your <sp-menu-item> entries?

 

For example:

<sp-picker value="b">
<sp-menu-item value="a">Option A</sp-menu-item>
<sp-menu-item value="b">Option B</sp-menu-item>
<sp-menu-item value="c">Option C</sp-menu-item>
</sp-picker>


In this case, Option B will be selected when the picker loads because its value matches the picker’s value attribute.

 

Maybe if you’re updating it dynamically in UXP/JS, you could also set it in a script?


const picker = document.querySelector("sp-picker");
picker.value = "b";


Would this give the preselected value? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines