Copilot commented on code in PR #3323:
URL: https://github.com/apache/apisix-dashboard/pull/3323#discussion_r2928870961


##########
src/components/Header/ThemeToggle.tsx:
##########
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { SegmentedControl, useMantineColorScheme } from '@mantine/core';
+import { useCallback, useEffect, useRef } from 'react';
+
+import IconDarkMode from '~icons/material-symbols/dark-mode';
+import IconDesktop from '~icons/material-symbols/desktop-windows';
+import IconLightMode from '~icons/material-symbols/light-mode';
+
+const TRANSITION_DURATION_MS = 200;
+
+const iconStyle = { width: 14, height: 14 } as const;
+
+const segmentData = [
+  { value: 'light', label: <IconLightMode style={iconStyle} /> },
+  { value: 'dark', label: <IconDarkMode style={iconStyle} /> },
+  { value: 'auto', label: <IconDesktop style={iconStyle} /> },
+];

Review Comment:
   SegmentedControl options are icon-only, so the underlying radio inputs 
likely have no accessible name. This makes the theme switcher hard/impossible 
to use with screen readers and forces e2e tests to rely on brittle DOM 
selectors. Consider adding text labels (can be visually hidden) or otherwise 
providing an accessible name for each segment (e.g., via hidden text in the 
label) so each option can be located via role/name.



##########
index.html:
##########
@@ -5,6 +5,20 @@
     <link rel="icon" type="image/svg+xml" href="/src/assets/apisix-logo.svg" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>Apache APISIX Dashboard</title>
+    <script>
+      try {
+        var scheme = localStorage.getItem('mantine-color-scheme-value');
+        if (scheme === 'dark' || scheme === 'light') {
+          document.documentElement.setAttribute('data-mantine-color-scheme', 
scheme);
+        } else {
+          var prefersDark = window.matchMedia && 
window.matchMedia('(prefers-color-scheme: dark)').matches;
+          document.documentElement.setAttribute(
+            'data-mantine-color-scheme',
+            prefersDark ? 'dark' : 'light'
+          );
+        }
+      } catch (e) {}

Review Comment:
   This inline color-scheme bootstrap script uses `var` declarations in the 
global scope and swallows all errors with an empty `catch`, which can make 
debugging failures (e.g., storage access restrictions) unnecessarily hard. 
Consider wrapping it in an IIFE and using `const`/`let`, and at least leave a 
short comment in the catch explaining why errors are intentionally ignored (or 
log in non-production).
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to