How to programatically open list on Mac

In the Chrome browser on Windows, when a <select> element receives focus, pressing the ENTER key will reveal the list of options. However, this is not the case on Mac. So far I have not found a way to do this programmatically, short of building a custom solution.

Below are the different approaches I have tried:

document.addEventListener('DOMContentLoaded', () => {

  // Approach 1: Native Focus + Click
  const select1 = document.getElementById('select1');
  select1.addEventListener('keydown', (event) => {
    if (event.key === 'Enter') {
      console.log('Approach 1: Native Focus + Click');
      select1.focus();
      select1.click();
    }
  });

  // Approach 2: Native Focus + Mousedown
  const select2 = document.getElementById('select2');
  select2.addEventListener('keydown', (event) => {
    if (event.key === 'Enter') {
      console.log('Approach 2: Native Focus + Mousedown');
      select2.focus();
      const mousedownEvent = new MouseEvent('mousedown', {
        bubbles: true,
        cancelable: true,
        view: window,
      });
      select2.dispatchEvent(mousedownEvent);
    }
  });

  // Approach 3: Native Focus + Simulate ArrowDown
  const select3 = document.getElementById('select3');
  select3.addEventListener('keydown', (event) => {
    if (event.key === 'Enter') {
      console.log('Approach 3: Native Focus + Simulate ArrowDown');
      select3.focus();
      const arrowDownEvent = new KeyboardEvent('keydown', {
        key: 'ArrowDown',
        code: 'ArrowDown',
        keyCode: 40,
        bubbles: true,
        cancelable: true,
      });
      select3.dispatchEvent(arrowDownEvent)
    }
  });

  // Approach 4: Custom Dropdown
  const customDropdown = document.getElementById('custom-dropdown');
  const customOptions = document.getElementById('custom-options');
  const customSelected = document.getElementById('custom-selected');

  customDropdown.addEventListener('keydown', (event) => {
    if (event.key === 'Enter') {
      console.log('Approach 4: Custom Dropdown (Simulated)');
      const isExpanded = customDropdown.getAttribute('aria-expanded') === 'true';
      customDropdown.setAttribute('aria-expanded', !isExpanded);
      customOptions.hidden = isExpanded;
    }
  });

  customOptions.addEventListener('click', (event) => {
    customSelected.textContent = event.target.textContent;
    customDropdown.setAttribute('aria-expanded', 'false');
    customOptions.hidden = true;
  });
});
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Experiment with Dropdown Approaches</title>
</head>
<body>
  <h1>Select Dropdown Approaches</h1>
  <p>Focus on each dropdown and press <strong>Enter</strong>. Check the console to see logs and experiment with different approaches.</p>

  <div>
    <h2>Approach 1: Native Focus + Click</h2>
    <label for="select1">Dropdown:</label>
    <select id="select1">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
    </select>
  </div>

  <div>
    <h2>Approach 2: Native Focus + Mousedown</h2>
    <label for="select2">Dropdown:</label>
    <select id="select2">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
    </select>
  </div>

  <div>
    <h2>Approach 3: Native Focus + Simulate ArrowDown</h2>
    <label for="select3">Dropdown:</label>
    <select id="select3">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
    </select>
  </div>

  <div>
    <h2>Approach 4: Custom Dropdown (Simulated)</h2>
    <div id="custom-dropdown" tabindex="0" role="combobox" aria-expanded="false">
      <div id="custom-selected">Select an option</div>
      <ul id="custom-options" role="listbox" hidden>
        <li role="option">Option 1</li>
        <li role="option">Option 2</li>
        <li role="option">Option 3</li>
      </ul>
    </div>
  </div>
</body>
</html>

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật