@daoyi/nmtl-ui 2.0.1-beta.110 → 2.0.1-beta.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -220,7 +220,7 @@ var useAutocomplete = (_ref => {
220
220
  };
221
221
  });
222
222
 
223
- var css_248z = ".autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n flex-wrap: wrap;\n padding: 0px 8px;\n}\n.autocomplete .MuiChip-deleteIcon {\n width: 16px;\n height: 16px;\n}\n.autocomplete__icon {\n font-size: 1.25rem;\n margin-right: 8px;\n cursor: pointer;\n}\n.autocomplete--showSearchIcon .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n display: flex;\n flex-wrap: nowrap;\n padding: 4px 8px;\n}";
223
+ var css_248z = "@charset \"UTF-8\";\n/* 下拉選項鍵盤高亮可視化(R39):上下鍵挑選時 MUI 只給 data-focus=\"true\"+\n action.hover(4% 黑)底色,對使用者幾乎不可見(WCAG 2.4.7 精神)。\n 比照 R30 選單選項聚焦模式=亮底+2px 虛線內縮完整框;彈窗為白底 paper(九專案皆未改色),\n #0f1315 對亮底對比 >12:1。選單以 Popper 掛在 body,選擇器須在 .autocomplete 之外 */\n/* 加上 listbox 父層提高特異度:MUI JSS 的同名規則注入較晚,同特異度時會蓋掉本檔背景色 */\n.MuiAutocomplete-listbox .MuiAutocomplete-option[data-focus=true] {\n background-color: rgba(0, 0, 0, 0.1);\n outline: 2px dashed #0f1315;\n outline-offset: -4px;\n}\n\n.autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n flex-wrap: wrap;\n padding: 0px 8px;\n}\n.autocomplete .MuiChip-deleteIcon {\n width: 16px;\n height: 16px;\n}\n.autocomplete__icon {\n font-size: 1.25rem;\n margin-right: 8px;\n cursor: pointer;\n}\n.autocomplete--showSearchIcon .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n display: flex;\n flex-wrap: nowrap;\n padding: 4px 8px;\n}";
224
224
  styleInject(css_248z);
225
225
 
226
226
  var Autocomplete = function Autocomplete(props) {
@@ -287,6 +287,10 @@ var Autocomplete = function Autocomplete(props) {
287
287
  var handleSearch = useRef(debounce_1(function (result) {
288
288
  return onSearch(result);
289
289
  }, 500)).current;
290
+ /* WCAG 2.4.3 renderAfterDefaultValueChange 重繪會使焦點掉到 body(NVDA 改從頁面頂端讀起、
291
+ 蓋掉 aria-live 播報)——unmount 前記錄焦點是否在元件內,remount 後還原 */
292
+ var rootRef = useRef(null);
293
+ var hadFocusRef = useRef(false);
290
294
 
291
295
  // 複選時 defaultValue 必須為Array
292
296
  // const currentDefaultValue = typeof defaultValue === 'string' && multiple ? undefined : getValueFromOptions(defaultValue);
@@ -297,10 +301,22 @@ var Autocomplete = function Autocomplete(props) {
297
301
  } : getValueFromOptions(defaultValue));
298
302
  }, [JSON.stringify(defaultValue)]);
299
303
  useEffect(function () {
300
- if (renderAfterDefaultValueChange) setRerender(false);
304
+ if (renderAfterDefaultValueChange) {
305
+ hadFocusRef.current = !!(rootRef.current && rootRef.current.contains(document.activeElement));
306
+ setRerender(false);
307
+ }
301
308
  }, [currentDefaultValue]); // defaultValue改變時強制rerender
302
309
  useEffect(function () {
303
- if (!rerender) setRerender(true);
310
+ if (!rerender) {
311
+ setRerender(true);
312
+ } else if (hadFocusRef.current) {
313
+ // remount 完成後把焦點還給輸入框(初載/返回時焦點不在元件內,不會搶焦點)
314
+ hadFocusRef.current = false;
315
+ setTimeout(function () {
316
+ var input = rootRef.current && rootRef.current.querySelector('input');
317
+ if (input) input.focus();
318
+ }, 0);
319
+ }
304
320
  }, [rerender]);
305
321
  /* 監聽result變化時才觸發onSearch */
306
322
  useEffect(function () {
@@ -312,6 +328,7 @@ var Autocomplete = function Autocomplete(props) {
312
328
 
313
329
  /* 這邊邏輯很複雜 變動需再三確認case */
314
330
  return /*#__PURE__*/React__default.createElement("div", {
331
+ ref: rootRef,
315
332
  className: classNames('autocomplete', {
316
333
  'autocomplete--showSearchIcon': searchIcon
317
334
  }, className)
@@ -1,4 +1,4 @@
1
- export { A as default } from './Autocomplete-8aa5b893.js';
1
+ export { A as default } from './Autocomplete-dd6540c5.js';
2
2
  import './_rollupPluginBabelHelpers-a52356f6.js';
3
3
  import 'react';
4
4
  import 'prop-types';
@@ -6,7 +6,7 @@ import { d as debounce_1 } from './debounce-127da66c.js';
6
6
  import { useHistory, useRouteMatch, NavLink } from 'react-router-dom';
7
7
  import { Typography, IconButton } from '@material-ui/core';
8
8
  import { SearchOutlined } from '@material-ui/icons';
9
- import { K as KeywordSearch } from './KeywordSearch-0640ae9a.js';
9
+ import { K as KeywordSearch } from './KeywordSearch-f56c8cb2.js';
10
10
  import { S as Select } from './Select-52ab5299.js';
11
11
  import { c as checkLanguageSupport, D as Drawer, d as defaultSupportLanguage } from './Drawer-b2edc79b.js';
12
12
  import { getIntl } from './globalConfig';
@@ -14,7 +14,7 @@ import { s as styleInject } from './style-inject.es-1f59c1d0.js';
14
14
  import './isObjectLike-e111475d.js';
15
15
  import './_commonjsHelpers-70de2c37.js';
16
16
  import 'axios';
17
- import './Autocomplete-8aa5b893.js';
17
+ import './Autocomplete-dd6540c5.js';
18
18
  import '@material-ui/lab';
19
19
  import './createSvgIcon-e3803ee1.js';
20
20
  import './defaultTheme-ed7746fe.js';
@@ -26,7 +26,7 @@ import './Empty-c6a44967.js';
26
26
  import './useTheme-d16d02d9.js';
27
27
  import './withTheme-2d778133.js';
28
28
 
29
- var css_248z = "@charset \"UTF-8\";\n.header {\n display: flex;\n align-items: center;\n background: rgba(255, 255, 255, 0.6);\n background-color: rgba(255, 255, 255, 0.6);\n padding: 12px 36px !important;\n position: fixed;\n top: 0;\n z-index: 10;\n width: 100% !important;\n transition: top 0.3s ease-in-out;\n box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);\n}\n.header__logo {\n display: flex;\n width: -moz-fit-content !important;\n width: fit-content !important;\n margin-right: 30px !important;\n cursor: pointer;\n}\n.header__logo__img {\n display: flex;\n align-items: center;\n}\n.header__logo__title {\n white-space: nowrap;\n margin-left: 1rem !important;\n font-size: 1.5rem !important;\n font-weight: 700 !important;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links {\n display: flex;\n justify-content: flex-end;\n padding-right: 14px;\n}\n.header__links a {\n text-decoration: none;\n}\n.header__links--full {\n flex: 1;\n}\n.header__links__item {\n color: rgba(0, 0, 0, 0.85);\n font-size: 1.125rem !important;\n font-weight: 500 !important;\n white-space: nowrap;\n padding: 6px 14px;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links__item--active .header__links__item {\n font-weight: 800 !important;\n background: transparent;\n border-radius: 45px;\n}\n.header__links__item:hover {\n font-weight: 800 !important;\n}\n.header__language {\n min-width: 100px !important;\n}\n.header__searchIcon {\n display: none !important;\n}\n@media screen and (max-width: 768px) {\n .header--smallUseSearchIcon .header__searchIcon {\n display: flex !important;\n margin-right: 10px !important;\n }\n .header--smallUseSearchIcon .keywordSearch {\n visibility: hidden;\n flex: 1;\n width: 0;\n }\n}\n.header--hide {\n top: -100px;\n}\n.header--focus .header__links {\n display: none;\n}\n.header .MuiTypography-root {\n width: 100%;\n display: flex;\n align-items: center;\n}\n.header .autocomplete {\n float: right;\n}\n.header .autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n padding: 1px 8px !important;\n}\n.header .keywordSearch {\n margin-right: 8px;\n}\n.header .keywordSearch--focus .autocomplete {\n width: 100% !important;\n}\n.header .keywordSearch--animation .autocomplete {\n width: 240px;\n transition: width 0.3s ease-in-out;\n}\n\n/* 避免寬度460以下炸版 */\n@media screen and (max-width: 460px) {\n .header .keywordSearch--animation .autocomplete {\n width: 100%;\n }\n}\n@media screen and (max-width: 768px) {\n .header {\n padding: 12px 15px !important;\n }\n .header__logo {\n margin-right: 16px !important;\n }\n .header__logo__title {\n display: none !important;\n }\n .header__links {\n display: none;\n }\n .header__links__item {\n font-size: 1rem !important;\n }\n .header__language {\n display: none !important;\n }\n .header--focus .header__logo {\n display: none !important;\n }\n\n .autocomplete__icon {\n display: none !important;\n }\n}";
29
+ var css_248z = "@charset \"UTF-8\";\n.header {\n display: flex;\n align-items: center;\n background: rgba(255, 255, 255, 0.6);\n background-color: rgba(255, 255, 255, 0.6);\n padding: 12px 36px !important;\n position: fixed;\n top: 0;\n z-index: 10;\n width: 100% !important;\n transition: top 0.3s ease-in-out;\n box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);\n}\n.header__logo {\n display: flex;\n width: -moz-fit-content !important;\n width: fit-content !important;\n margin-right: 30px !important;\n cursor: pointer;\n text-decoration: none;\n}\n.header__logo__img {\n display: flex;\n align-items: center;\n}\n.header__logo__title {\n white-space: nowrap;\n margin-left: 1rem !important;\n font-size: 1.5rem !important;\n font-weight: 700 !important;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links {\n display: flex;\n justify-content: flex-end;\n padding-right: 14px;\n}\n.header__links a {\n text-decoration: none;\n}\n.header__links--full {\n flex: 1;\n}\n.header__links__item {\n color: rgba(0, 0, 0, 0.85);\n font-size: 1.125rem !important;\n font-weight: 500 !important;\n white-space: nowrap;\n padding: 6px 14px;\n font-family: \"Noto Sans TC\" !important;\n}\n.header__links__item--active .header__links__item {\n font-weight: 800 !important;\n background: transparent;\n border-radius: 45px;\n}\n.header__links__item:hover {\n font-weight: 800 !important;\n}\n.header__language {\n min-width: 100px !important;\n}\n.header__searchIcon {\n display: none !important;\n}\n@media screen and (max-width: 768px) {\n .header--smallUseSearchIcon .header__searchIcon {\n display: flex !important;\n margin-right: 10px !important;\n }\n .header--smallUseSearchIcon .keywordSearch {\n visibility: hidden;\n flex: 1;\n width: 0;\n }\n}\n.header--hide {\n top: -100px;\n}\n.header--focus .header__links {\n display: none;\n}\n.header .MuiTypography-root {\n width: 100%;\n display: flex;\n align-items: center;\n}\n.header .autocomplete {\n float: right;\n}\n.header .autocomplete .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n padding: 1px 8px !important;\n}\n.header .keywordSearch {\n margin-right: 8px;\n}\n.header .keywordSearch--focus .autocomplete {\n width: 100% !important;\n}\n.header .keywordSearch--animation .autocomplete {\n width: 240px;\n transition: width 0.3s ease-in-out;\n}\n\n/* 避免寬度460以下炸版 */\n@media screen and (max-width: 460px) {\n .header .keywordSearch--animation .autocomplete {\n width: 100%;\n }\n}\n@media screen and (max-width: 768px) {\n .header {\n padding: 12px 15px !important;\n }\n .header__logo {\n margin-right: 16px !important;\n }\n .header__logo__title {\n display: none !important;\n }\n .header__links {\n display: none;\n }\n .header__links__item {\n font-size: 1rem !important;\n }\n .header__language {\n display: none !important;\n }\n .header--focus .header__logo {\n display: none !important;\n }\n\n .autocomplete__icon {\n display: none !important;\n }\n}";
30
30
  styleInject(css_248z);
31
31
 
32
32
  var showDarkModeSwitch = false;
@@ -72,6 +72,7 @@ var Header = function Header(props) {
72
72
  setMenuOpen(false);
73
73
  }, [search]);
74
74
  return /*#__PURE__*/React__default.createElement("div", {
75
+ role: "banner",
75
76
  className: classNames('MuiPaper-root', 'header', {
76
77
  'header--smallUseSearchIcon': smallUseSearchIcon
77
78
  }, {
@@ -79,22 +80,16 @@ var Header = function Header(props) {
79
80
  }, {
80
81
  'header--focus': menuOpen
81
82
  }, className)
82
- }, /*#__PURE__*/React__default.createElement("div", {
83
+ }, /*#__PURE__*/React__default.createElement(NavLink, {
84
+ to: "/".concat(locale, "/main/home"),
83
85
  className: "header__logo",
84
- role: "link",
85
- tabIndex: 0,
86
- "aria-label": getIntl().formatMessage({
86
+ "aria-label": title ? getIntl().formatMessage({
87
+ id: 'aria.header.logoHomeWithTitle'
88
+ }, {
89
+ title: title
90
+ }) : getIntl().formatMessage({
87
91
  id: 'aria.header.logoHome'
88
- }),
89
- onClick: function onClick() {
90
- return history.push("/".concat(locale, "/main/home"));
91
- },
92
- onKeyDown: function onKeyDown(event) {
93
- if (event.key === 'Enter') {
94
- event.preventDefault();
95
- history.push("/".concat(locale, "/main/home"));
96
- }
97
- }
92
+ })
98
93
  }, logo && /*#__PURE__*/React__default.createElement("div", {
99
94
  className: "header__logo__img"
100
95
  }, logo), !menuOpen && title && /*#__PURE__*/React__default.createElement(Typography, {
@@ -109,9 +104,12 @@ var Header = function Header(props) {
109
104
  menuOpen: menuOpen,
110
105
  setMenuOpen: setMenuOpen,
111
106
  onSearch: onSearch
112
- }), /*#__PURE__*/React__default.createElement("div", {
107
+ }), /*#__PURE__*/React__default.createElement("nav", {
113
108
  className: classNames('header__links', {
114
109
  'header__links--full': !searchAPI
110
+ }),
111
+ "aria-label": getIntl().formatMessage({
112
+ id: 'aria.header.navigation'
115
113
  })
116
114
  }, (Array.isArray(pages) ? pages : []).filter(function (_ref) {
117
115
  var showInHeader = _ref.showInHeader;
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
4
4
  import { c as classNames } from './index-b76a85f4.js';
5
5
  import axios from 'axios';
6
6
  import { s as styleInject } from './style-inject.es-1f59c1d0.js';
7
- import { A as Autocomplete } from './Autocomplete-8aa5b893.js';
7
+ import { A as Autocomplete } from './Autocomplete-dd6540c5.js';
8
8
 
9
9
  var css_248z = ".keywordSearch {\n border-radius: 4px;\n width: 100%;\n margin-right: 14px;\n}\n.keywordSearch--animation .autocomplete {\n transition: max-width 0.3s ease-out;\n max-width: 240px;\n}\n.keywordSearch--focus {\n flex: 1;\n}\n.keywordSearch--focus .autocomplete {\n max-width: 100%;\n}\n.keywordSearch .MuiAutocomplete-hasPopupIcon.MuiAutocomplete-hasClearIcon .MuiAutocomplete-inputRoot[class*=MuiOutlinedInput-root] {\n border-radius: 10px;\n background-color: #ffffff66;\n}";
10
10
  styleInject(css_248z);
@@ -1,11 +1,11 @@
1
- export { K as default } from './KeywordSearch-0640ae9a.js';
1
+ export { K as default } from './KeywordSearch-f56c8cb2.js';
2
2
  import './_rollupPluginBabelHelpers-a52356f6.js';
3
3
  import 'react';
4
4
  import 'prop-types';
5
5
  import './index-b76a85f4.js';
6
6
  import 'axios';
7
7
  import './style-inject.es-1f59c1d0.js';
8
- import './Autocomplete-8aa5b893.js';
8
+ import './Autocomplete-dd6540c5.js';
9
9
  import './debounce-127da66c.js';
10
10
  import './isObjectLike-e111475d.js';
11
11
  import './_commonjsHelpers-70de2c37.js';
@@ -59,6 +59,8 @@ var zhtw = {
59
59
  "aria.header.searchOpen": "開啟搜尋",
60
60
  "aria.header.menuOpen": "開啟主選單",
61
61
  "aria.header.logoHome": "回首頁",
62
+ "aria.header.logoHomeWithTitle": "{title},回首頁",
63
+ "aria.header.navigation": "主選單",
62
64
  "aria.autocomplete.search": "執行搜尋",
63
65
  "aria.modal.close": "關閉視窗",
64
66
  "aria.newWindow": "(另開新視窗)",
@@ -138,6 +140,8 @@ var zhcn = {
138
140
  "aria.header.searchOpen": "开启搜寻",
139
141
  "aria.header.menuOpen": "开启主选单",
140
142
  "aria.header.logoHome": "回首页",
143
+ "aria.header.logoHomeWithTitle": "{title},回首页",
144
+ "aria.header.navigation": "主选单",
141
145
  "aria.autocomplete.search": "执行搜寻",
142
146
  "aria.modal.close": "关闭视窗",
143
147
  "aria.newWindow": "(另开新视窗)",
@@ -217,6 +221,8 @@ var enus = {
217
221
  "aria.header.searchOpen": "Open search",
218
222
  "aria.header.menuOpen": "Open main menu",
219
223
  "aria.header.logoHome": "Back to home",
224
+ "aria.header.logoHomeWithTitle": "{title}, back to home",
225
+ "aria.header.navigation": "Main menu",
220
226
  "aria.autocomplete.search": "Search",
221
227
  "aria.modal.close": "Close dialog",
222
228
  "aria.newWindow": " (opens in new window)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daoyi/nmtl-ui",
3
- "version": "2.0.1-beta.110",
3
+ "version": "2.0.1-beta.113",
4
4
  "description": "This project is to be used as a starter kit for building React component using Storybook and Rollup",
5
5
  "author": "daoyi",
6
6
  "main": "lib/index.js",