@@ -1461,6 +1461,8 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1461
1461
selectElement . setAttribute ( "id" , id ) ;
1462
1462
selectElement . tabIndex = DEFAULT_TAB_INDEX ;
1463
1463
1464
+ let addAnEmptyEntry = this . data . combo && this . data . options . length > 0 ;
1465
+
1464
1466
if ( ! this . data . combo ) {
1465
1467
// List boxes have a size and (optionally) multiple selection.
1466
1468
selectElement . size = this . data . options . length ;
@@ -1486,10 +1488,27 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1486
1488
}
1487
1489
if ( storedData . value . includes ( option . exportValue ) ) {
1488
1490
optionElement . setAttribute ( "selected" , true ) ;
1491
+ addAnEmptyEntry = false ;
1489
1492
}
1490
1493
selectElement . appendChild ( optionElement ) ;
1491
1494
}
1492
1495
1496
+ let removeEmptyEntry = null ;
1497
+ if ( addAnEmptyEntry ) {
1498
+ const noneOptionElement = document . createElement ( "option" ) ;
1499
+ noneOptionElement . value = " " ;
1500
+ noneOptionElement . setAttribute ( "hidden" , true ) ;
1501
+ noneOptionElement . setAttribute ( "selected" , true ) ;
1502
+ selectElement . insertBefore ( noneOptionElement , selectElement . firstChild ) ;
1503
+
1504
+ removeEmptyEntry = ( ) => {
1505
+ noneOptionElement . remove ( ) ;
1506
+ selectElement . removeEventListener ( "input" , removeEmptyEntry ) ;
1507
+ removeEmptyEntry = null ;
1508
+ } ;
1509
+ selectElement . addEventListener ( "input" , removeEmptyEntry ) ;
1510
+ }
1511
+
1493
1512
const getValue = ( event , isExport ) => {
1494
1513
const name = isExport ? "value" : "textContent" ;
1495
1514
const options = event . target . options ;
@@ -1514,6 +1533,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1514
1533
selectElement . addEventListener ( "updatefromsandbox" , jsEvent => {
1515
1534
const actions = {
1516
1535
value ( event ) {
1536
+ removeEmptyEntry ?. ( ) ;
1517
1537
const value = event . detail . value ;
1518
1538
const values = new Set ( Array . isArray ( value ) ? value : [ value ] ) ;
1519
1539
for ( const option of selectElement . options ) {
0 commit comments