Re: [csswg-drafts] [mediaqueries-5] Script control of (prefers-*) queries (#6517)

> Although I don't fully understand how the API shape https://github.com/WICG/web-preferences-api/issues/7#issuecomment-1721930664 solves this so it would be good to see an example.

The proposal and your idea for improvement is basically the same only difference is I've done values as an array because *technically* they could match multiple values at once. This isn't very ergonomic though so I would rather just do .value and accept that these media queries are single value at a time.

```js
button.onclick = () => {
 const newVal = (navigator.preferences.colorScheme.values[0] === 'dark') ? 'light' : 'dark';
 navigator.preferences.colorScheme.requestOverride(newVal)
  .then(() => {
    // The preference override was successful.
  })
  .catch((error) => {
    // The preference override request was rejected.
  });
};
```

-- 
GitHub Notification of comment by lukewarlow
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6517#issuecomment-1834366670 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 30 November 2023 18:50:35 UTC