@mackin.com/styleguide 11.1.0 → 11.2.0

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.
package/index.d.ts CHANGED
@@ -833,6 +833,10 @@ interface SearchBoxProps extends BaseProps$1 {
833
833
  noSubmitWhenEmpty?: boolean;
834
834
  /** The submit button will change to clear if present and there is a value. */
835
835
  onClear?: () => void;
836
+ /** Not localized. Defaults to 'Search'. */
837
+ searchButtonAriaLabel?: string;
838
+ /** Not localized. Defaults to 'Clear'. */
839
+ clearButtonAriaLabel?: string;
836
840
  }
837
841
  declare const SearchBox: React.ForwardRefExoticComponent<Omit<SearchBoxProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
838
842
 
package/index.esm.js CHANGED
@@ -4259,9 +4259,9 @@ const useWaiting = (func) => {
4259
4259
  };
4260
4260
 
4261
4261
  const SearchBox = React.forwardRef((props, ref) => {
4262
- const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear"]);
4262
+ const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear, searchButtonAriaLabel, clearButtonAriaLabel } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear", "searchButtonAriaLabel", "clearButtonAriaLabel"]);
4263
+ const searchBoxMarkerClass = 'searchBoxInput';
4263
4264
  const [waiting, handleSubmit] = useWaiting(async () => {
4264
- var _a, _b;
4265
4265
  if (noForm) {
4266
4266
  return;
4267
4267
  }
@@ -4271,12 +4271,17 @@ const SearchBox = React.forwardRef((props, ref) => {
4271
4271
  if ((noSubmitWhenEmpty !== null && noSubmitWhenEmpty !== void 0 ? noSubmitWhenEmpty : true) && !props.value) {
4272
4272
  return;
4273
4273
  }
4274
- // the active element will be the input. if the submit action changes props.value it will
4274
+ // the active element should be the input. if the submit action changes props.value it will
4275
4275
  // be ignored due to Inputs focused handling.
4276
- if (document.activeElement) {
4277
- (_b = (_a = document.activeElement).blur) === null || _b === void 0 ? void 0 : _b.call(_a);
4276
+ const focusElement = document.activeElement;
4277
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4278
+ focusElement.blur();
4278
4279
  }
4279
- return onSubmit();
4280
+ return onSubmit().then(() => {
4281
+ if (focusElement) {
4282
+ focusElement.focus();
4283
+ }
4284
+ });
4280
4285
  });
4281
4286
  const theme = useThemeSafely();
4282
4287
  const buttonStyles = cx(css({
@@ -4285,10 +4290,10 @@ const SearchBox = React.forwardRef((props, ref) => {
4285
4290
  }), buttonClassName);
4286
4291
  let clearButton;
4287
4292
  if (onClear && !!props.value) {
4288
- clearButton = (React.createElement(Button, { onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4293
+ clearButton = (React.createElement(Button, { "aria-label": clearButtonAriaLabel, onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4289
4294
  React.createElement(Icon, { id: "clear" })));
4290
4295
  }
4291
- const saveButton = (React.createElement(Button, { tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4296
+ const saveButton = (React.createElement(Button, { "aria-label": searchButtonAriaLabel, tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4292
4297
  React.createElement(Icon, { id: waiting ? 'waiting' : 'search', spin: waiting })));
4293
4298
  const rightControls = clearButton ? React.createElement(React.Fragment, null,
4294
4299
  clearButton,
@@ -4299,12 +4304,29 @@ const SearchBox = React.forwardRef((props, ref) => {
4299
4304
  paddingRight: `calc(${theme.controls.height} + ${theme.controls.heightSmall})`
4300
4305
  });
4301
4306
  }
4302
- const input = (React.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: cx(clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4307
+ const input = (React.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: cx(searchBoxMarkerClass, clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4303
4308
  const searchBoxWrapperStyles = cx(css({
4304
4309
  label: 'SearchBox'
4305
4310
  }), wrapperClassName);
4306
4311
  if (!noForm) {
4307
- return (React.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit }, input));
4312
+ return (React.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit, onKeyDown: e => {
4313
+ if (e.code === 'Escape' && onClear) {
4314
+ e.stopPropagation();
4315
+ e.preventDefault();
4316
+ // the active element should be the input. if the clear action changes props.value it will
4317
+ // be ignored due to Inputs focused handling.
4318
+ const focusElement = document.activeElement;
4319
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4320
+ focusElement.blur();
4321
+ }
4322
+ onClear();
4323
+ if (focusElement) {
4324
+ setTimeout(() => {
4325
+ focusElement.focus();
4326
+ }, 0);
4327
+ }
4328
+ }
4329
+ } }, input));
4308
4330
  }
4309
4331
  return (React.createElement("div", { className: searchBoxWrapperStyles }, input));
4310
4332
  });
package/index.js CHANGED
@@ -4277,9 +4277,9 @@ const useWaiting = (func) => {
4277
4277
  };
4278
4278
 
4279
4279
  const SearchBox = React__namespace.forwardRef((props, ref) => {
4280
- const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear"]);
4280
+ const { wrapperClassName, buttonClassName, inputWrapperClassName, inputClassName, onSubmit, noForm, noSubmitWhenEmpty, onClear, searchButtonAriaLabel, clearButtonAriaLabel } = props, inputProps = __rest(props, ["wrapperClassName", "buttonClassName", "inputWrapperClassName", "inputClassName", "onSubmit", "noForm", "noSubmitWhenEmpty", "onClear", "searchButtonAriaLabel", "clearButtonAriaLabel"]);
4281
+ const searchBoxMarkerClass = 'searchBoxInput';
4281
4282
  const [waiting, handleSubmit] = useWaiting(async () => {
4282
- var _a, _b;
4283
4283
  if (noForm) {
4284
4284
  return;
4285
4285
  }
@@ -4289,12 +4289,17 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4289
4289
  if ((noSubmitWhenEmpty !== null && noSubmitWhenEmpty !== void 0 ? noSubmitWhenEmpty : true) && !props.value) {
4290
4290
  return;
4291
4291
  }
4292
- // the active element will be the input. if the submit action changes props.value it will
4292
+ // the active element should be the input. if the submit action changes props.value it will
4293
4293
  // be ignored due to Inputs focused handling.
4294
- if (document.activeElement) {
4295
- (_b = (_a = document.activeElement).blur) === null || _b === void 0 ? void 0 : _b.call(_a);
4294
+ const focusElement = document.activeElement;
4295
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4296
+ focusElement.blur();
4296
4297
  }
4297
- return onSubmit();
4298
+ return onSubmit().then(() => {
4299
+ if (focusElement) {
4300
+ focusElement.focus();
4301
+ }
4302
+ });
4298
4303
  });
4299
4304
  const theme = useThemeSafely();
4300
4305
  const buttonStyles = css.cx(css.css({
@@ -4303,10 +4308,10 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4303
4308
  }), buttonClassName);
4304
4309
  let clearButton;
4305
4310
  if (onClear && !!props.value) {
4306
- clearButton = (React__namespace.createElement(Button, { onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4311
+ clearButton = (React__namespace.createElement(Button, { "aria-label": clearButtonAriaLabel, onClick: onClear, tabIndex: -1, disabled: waiting, className: buttonStyles, variant: "icon", small: true },
4307
4312
  React__namespace.createElement(Icon, { id: "clear" })));
4308
4313
  }
4309
- const saveButton = (React__namespace.createElement(Button, { tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4314
+ const saveButton = (React__namespace.createElement(Button, { "aria-label": searchButtonAriaLabel, tabIndex: -1, disabled: waiting, readOnly: !props.onSubmit, type: "submit", className: buttonStyles, variant: "icon", small: true },
4310
4315
  React__namespace.createElement(Icon, { id: waiting ? 'waiting' : 'search', spin: waiting })));
4311
4316
  const rightControls = clearButton ? React__namespace.createElement(React__namespace.Fragment, null,
4312
4317
  clearButton,
@@ -4317,12 +4322,29 @@ const SearchBox = React__namespace.forwardRef((props, ref) => {
4317
4322
  paddingRight: `calc(${theme.controls.height} + ${theme.controls.heightSmall})`
4318
4323
  });
4319
4324
  }
4320
- const input = (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: css.cx(clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4325
+ const input = (React__namespace.createElement(TextInput, Object.assign({}, inputProps, { ref: ref, wrapperClassName: inputWrapperClassName, className: css.cx(searchBoxMarkerClass, clearButtonInputStyles, inputClassName), rightControl: rightControls })));
4321
4326
  const searchBoxWrapperStyles = css.cx(css.css({
4322
4327
  label: 'SearchBox'
4323
4328
  }), wrapperClassName);
4324
4329
  if (!noForm) {
4325
- return (React__namespace.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit }, input));
4330
+ return (React__namespace.createElement(Form, { role: "search", className: searchBoxWrapperStyles, onSubmit: handleSubmit, onKeyDown: e => {
4331
+ if (e.code === 'Escape' && onClear) {
4332
+ e.stopPropagation();
4333
+ e.preventDefault();
4334
+ // the active element should be the input. if the clear action changes props.value it will
4335
+ // be ignored due to Inputs focused handling.
4336
+ const focusElement = document.activeElement;
4337
+ if (focusElement && focusElement.classList.contains(searchBoxMarkerClass)) {
4338
+ focusElement.blur();
4339
+ }
4340
+ onClear();
4341
+ if (focusElement) {
4342
+ setTimeout(() => {
4343
+ focusElement.focus();
4344
+ }, 0);
4345
+ }
4346
+ }
4347
+ } }, input));
4326
4348
  }
4327
4349
  return (React__namespace.createElement("div", { className: searchBoxWrapperStyles }, input));
4328
4350
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "11.1.0",
3
+ "version": "11.2.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "module": "./index.esm.js",