|
32 | 32 | <li><a href="#text-box">TextBox</a></li> |
33 | 33 | <li><a href="#slider">Slider</a></li> |
34 | 34 | <li><a href="#combo-box">ComboBox</a></li> |
35 | | - <li><a href="#dropdown">Dropdown</a></li> |
| 35 | + <li><a href="#list-box">ListBox</a></li> |
36 | 36 | <li> |
37 | 37 | <a href="#window">Window</a> |
38 | 38 | <ul> |
|
492 | 492 | </ul> |
493 | 493 |
|
494 | 494 | <%- example(` |
495 | | - <div class="combo-box"> |
496 | | - <input type="text" role="combobox" value="Regular" aria-controls="example${getNewId()}" /> |
497 | | - <ul role="listbox" id="example${getCurrentId()}" tabindex="-1"> |
| 495 | + <div class="combo-box" style="width: fit-content"> |
| 496 | + <input type="text" id="example${getNewId()}-input" role="combobox" value="Regular" aria-controls="example${getCurrentId()}-listbox" /> |
| 497 | + <ul role="listbox" id="example${getCurrentId()}-listbox" tabindex="-1"> |
498 | 498 | <li role="option" aria-selected="true">Regular</li> |
499 | 499 | <li role="option">Italic</li> |
500 | 500 | <li role="option">Bold</li> |
|
512 | 512 | </ul> |
513 | 513 |
|
514 | 514 | <%- example(` |
515 | | - <div class="combo-box" width="200px"> |
516 | | - <input type="text" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="example${getNewId()}" /> |
| 515 | + <div class="combo-box" style="width: fit-content"> |
| 516 | + <input type="text" id="example${getNewId()}-input" role="combobox" value="h:mm:ss tt" aria-haspopup="listbox" aria-expanded="false" aria-controls="example${getCurrentId()}-listbox" /> |
517 | 517 | <button type="button" tabindex="-1"></button> |
518 | | - <ul role="listbox" id="example${getCurrentId()}" tabindex="-1"> |
519 | | - <li role="option">h:mm:ss tt</li> |
| 518 | + <ul role="listbox" id="example${getCurrentId()}-listbox" tabindex="-1"> |
| 519 | + <li role="option" aria-selected="true">h:mm:ss tt</li> |
520 | 520 | <li role="option">hh:mm:ss tt</li> |
521 | 521 | <li role="option">H:mm:ss</li> |
522 | 522 | <li role="option">HH:mm:ss</li> |
523 | 523 | </ul> |
524 | 524 | </div> |
525 | 525 | `) %> |
| 526 | + |
| 527 | + <p> |
| 528 | + For more options of the list box, see the <a href="#list-box">ListBox</a> section. |
| 529 | + </p> |
526 | 530 | </div> |
527 | 531 | </section> |
528 | 532 |
|
529 | 533 | <section class="component"> |
530 | | - <h3 id="dropdown">Dropdown</h3> |
| 534 | + <h3 id="list-box">ListBox</h3> |
531 | 535 | <div> |
532 | 536 | <blockquote> |
533 | | - A <em>drop-down list box</em> allows the selection of only a |
534 | | - single item from a list. In its closed state, the control displays |
535 | | - the current value for the control. The user opens the list to change |
536 | | - the value. |
| 537 | + A <em>list box</em> is a control for displaying a list of choices for the user. |
537 | 538 |
|
538 | 539 | <footer> |
539 | | - — Microsoft Windows User Experience p. 175 |
| 540 | + — Microsoft Windows User Experience p. 170 |
540 | 541 | </footer> |
541 | 542 | </blockquote> |
542 | 543 |
|
543 | 544 | <p> |
544 | | - Dropdowns can be rendered by using the <code>select</code> and <code>option</code> |
545 | | - elements. |
| 545 | + The simplest way to render a list box is by using the <code>select</code> element with a <code>multiple</code> attribute specified. |
546 | 546 | </p> |
547 | 547 |
|
548 | 548 | <%- example(` |
549 | | - <select> |
| 549 | + <select multiple> |
550 | 550 | <option>5 - Incredible!</option> |
551 | | - <option>4 - Great!</option> |
| 551 | + <option selected>4 - Great!</option> |
552 | 552 | <option>3 - Pretty good</option> |
553 | 553 | <option>2 - Not so great</option> |
554 | 554 | <option>1 - Unfortunate</option> |
555 | 555 | </select> |
556 | 556 | `) %> |
557 | 557 |
|
558 | 558 | <p> |
559 | | - By default, the first option will be selected. You can change this by |
560 | | - giving one of your <code>option</code> elements the <code>selected</code> |
561 | | - attribute. |
| 559 | + The complex way is using a combination of the <code>ul</code>/<code>li</code> elements with the role attributes. |
562 | 560 | </p> |
563 | 561 |
|
564 | 562 | <%- example(` |
565 | | - <select> |
566 | | - <option>5 - Incredible!</option> |
567 | | - <option>4 - Great!</option> |
568 | | - <option selected>3 - Pretty good</option> |
569 | | - <option>2 - Not so great</option> |
570 | | - <option>1 - Unfortunate</option> |
571 | | - </select> |
| 563 | + <ul role="listbox" tabindex="0" style="width: fit-content"> |
| 564 | + <li role="option" aria-selected="true">Bitmap Image</li> |
| 565 | + <li role="option">Image Document</li> |
| 566 | + <li role="option">Media Clip</li> |
| 567 | + <li role="option">Wave Sound</li> |
| 568 | + <li role="option">WordPad Document</li> |
| 569 | + </ul> |
| 570 | + `) %> |
| 571 | + |
| 572 | + <p> |
| 573 | + To remove the scroll bar of the list box, use the <code>no-scroll</code> class. |
| 574 | + </p> |
| 575 | + |
| 576 | + <%- example(` |
| 577 | + <ul role="listbox" class="no-scroll" tabindex="0" style="width: 150px"> |
| 578 | + <li role="option">Edit</li> |
| 579 | + <li role="option">Open</li> |
| 580 | + <li role="option">Print</li> |
| 581 | + </ul> |
| 582 | + `) %> |
| 583 | + |
| 584 | + <blockquote> |
| 585 | + A <em>drop-down list box</em> allows the selection of only a single item from a list; the difference is that the list is displayed on demand. In its closed state, the control displays the current value for the control. |
| 586 | + |
| 587 | + <footer> |
| 588 | + — Microsoft Windows User Experience p. 175 |
| 589 | + </footer> |
| 590 | + </blockquote> |
| 591 | + |
| 592 | + <p> |
| 593 | + A drop-down can be rendered in 2 ways. The first is using the native <code>select</code> and <code>option</code>. The second is using a text <code>input</code>, a <code>button</code>, a parent <code>ul</code>, and children <code>li</code> together, wrapped inside a container element with the <code>list-box</code> class. For accessibility, follow the minimum requirements below: |
| 594 | + </p> |
| 595 | + |
| 596 | + <ul> |
| 597 | + <li>Add <code>aria-haspopup="listbox"</code> and <code>aria-expanded</code> attributes to the text <code>input</code></li> |
| 598 | + <li> |
| 599 | + Specify the relationship between the list box and the text box by combining the <code>id</code> of the <code>listbox</code> with the <code>aria-controls</code> attribute on the text <code>input</code> |
| 600 | + </li> |
| 601 | + </ul> |
| 602 | + |
| 603 | + <%- example(` |
| 604 | + <div class="list-box" style="width: fit-content"> |
| 605 | + <input type="text" id="example${getNewId()}-input" aria-haspopup="listbox" value="True Color (24 bit)" aria-expanded="false" aria-controls="example${getCurrentId()}-listbox" readonly /> |
| 606 | + <button type="button" tabindex="-1"></button> |
| 607 | + <ul id="example${getCurrentId()}-listbox" role="listbox" tabindex="-1"> |
| 608 | + <li role="option">Monochrome</li> |
| 609 | + <li role="option">16 Color</li> |
| 610 | + <li role="option">256 Color</li> |
| 611 | + <li role="option">High Color (16 bit)</li> |
| 612 | + <li role="option" aria-selected="true">True Color (24 bit)</li> |
| 613 | + </ul> |
| 614 | + </div> |
| 615 | + `) %> |
| 616 | + |
| 617 | + <blockquote> |
| 618 | + Although most list boxes are single-selection lists, some contexts require the user to choose more than one item. <em>Multiple-selection list boxes</em> support this functionality. |
| 619 | + |
| 620 | + <footer> |
| 621 | + — Microsoft Windows User Experience p. 176 |
| 622 | + </footer> |
| 623 | + </blockquote> |
| 624 | + |
| 625 | + <p>A multiple-selection list box can be rendered by adding the <code>aria-multiselectable</code> attribute to the <code>listbox</code>, along with checkboxes.</p> |
| 626 | + |
| 627 | + <%- example(` |
| 628 | + <ul role="listbox" tabindex="0" aria-multiselectable="true" style="width: fit-content"> |
| 629 | + <li role="option"> |
| 630 | + <input type="checkbox" id="example${getNewId()}-checkbox-1" tabindex="-1"> |
| 631 | + <label for="example${getCurrentId()}-checkbox-1">Yearly Statistic</label> |
| 632 | + </li> |
| 633 | + <li role="option"> |
| 634 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-2" tabindex="-1"> |
| 635 | + <label for="example${getCurrentId()}-checkbox-2">Financial Summary</label> |
| 636 | + </li> |
| 637 | + <li role="option"> |
| 638 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-3" tabindex="-1"> |
| 639 | + <label for="example${getCurrentId()}-checkbox-3">Samson Account</label> |
| 640 | + </li> |
| 641 | + <li role="option"> |
| 642 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-4" tabindex="-1"> |
| 643 | + <label for="example${getCurrentId()}-checkbox-4">Lukison Review</label> |
| 644 | + </li> |
| 645 | + </ul> |
| 646 | + `) %> |
| 647 | + |
| 648 | + <p>Group options by wrapping them in a <code>ul</code> with parent <code>li</code> with the <code>role="group"</code> attribute. |
| 649 | + To label a group of options, use a child <code>span</code> inside the parent <code>li</code> and reference its id in the <code>aria-labelledby</code> attribute of the <code>li</code>.</p> |
| 650 | + |
| 651 | + <%- example(` |
| 652 | + <ul role="listbox" tabindex="0" aria-multiselectable="true" style="width: fit-content"> |
| 653 | + <li role="group" aria-labelledby="example${getNewId()}-group-1"> |
| 654 | + <span id="example${getCurrentId()}-group-1">Browsing</span> |
| 655 | + <ul> |
| 656 | + <li role="option"> |
| 657 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-1" tabindex="-1"> |
| 658 | + <label for="example${getCurrentId()}-checkbox-1">Enable page transitions</label> |
| 659 | + </li> |
| 660 | + <li role="option"> |
| 661 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-2" tabindex="-1"> |
| 662 | + <label for="example${getCurrentId()}-checkbox-2">Use smooth scrolling</label> |
| 663 | + </li> |
| 664 | + </ul> |
| 665 | + </li> |
| 666 | + <li role="group" aria-labelledby="example${getCurrentId()}-group-2"> |
| 667 | + <span id="example${getCurrentId()}-group-2">Multimedia</span> |
| 668 | + <ul> |
| 669 | + <li role="option"> |
| 670 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-3" tabindex="-1"> |
| 671 | + <label for="example${getCurrentId()}-checkbox-3">Play animations</label> |
| 672 | + </li> |
| 673 | + <li role="option"> |
| 674 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-4" tabindex="-1"> |
| 675 | + <label for="example${getCurrentId()}-checkbox-4">Play sounds</label> |
| 676 | + </li> |
| 677 | + <li role="option"> |
| 678 | + <input type="checkbox" id="example${getCurrentId()}-checkbox-5" tabindex="-1"> |
| 679 | + <label for="example${getCurrentId()}-checkbox-5">Show pictures</label> |
| 680 | + </li> |
| 681 | + </ul> |
| 682 | + </li> |
| 683 | + </ul> |
572 | 684 | `) %> |
573 | 685 | </div> |
574 | 686 | </section> |
|
0 commit comments