@khanacademy/wonder-blocks-icon-button 5.1.4 → 5.1.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @khanacademy/wonder-blocks-icon-button
2
2
 
3
+ ## 5.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 9092363d: Fixes keyboard behavior on IconButton:
8
+ - Allows triggering onClick when Enter is pressed. - Fixes the active state from not being sticky on mobile devices.
9
+
10
+ ## 5.1.5
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [171e3b01]
15
+ - @khanacademy/wonder-blocks-icon@4.0.0
16
+
3
17
  ## 5.1.4
4
18
 
5
19
  ### Patch Changes
@@ -9,6 +9,16 @@ type Props = SharedProps & {
9
9
  * passed in as the `<a>` tag's `href` if present.
10
10
  */
11
11
  href?: string;
12
+ /**
13
+ * Listens for keydown events on the button. This is useful for preventing
14
+ * default behavior when the user presses the spacebar or enter key.
15
+ */
16
+ onKeyDown?: (e: React.KeyboardEvent) => unknown;
17
+ /**
18
+ * Listens for keyup events on the button. This is useful for triggering
19
+ * actions when the user presses the spacebar or enter key.
20
+ */
21
+ onKeyUp?: (e: React.KeyboardEvent) => unknown;
12
22
  };
13
23
  declare const IconButtonCore: React.ForwardRefExoticComponent<Props & React.RefAttributes<typeof Link | HTMLButtonElement | HTMLAnchorElement>>;
14
24
  export default IconButtonCore;
package/dist/es/index.js CHANGED
@@ -374,6 +374,15 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
374
374
  borderRadius: theme.border.radius.default,
375
375
  outlineWidth: theme.border.width.default
376
376
  }, kindOverrides[":hover"]),
377
+ ["@media not (hover: hover)"]: {
378
+ ":hover": {
379
+ boxShadow: "none",
380
+ color: defaultColor,
381
+ borderRadius: theme.border.radius.default,
382
+ outline: "none",
383
+ backgroundColor: "transparent"
384
+ }
385
+ },
377
386
  ":focus": {
378
387
  boxShadow: `0 0 0 ${theme.border.width.default}px ${defaultStrokeColor}`,
379
388
  borderRadius: theme.border.radius.default
@@ -435,6 +444,20 @@ const IconButton = React.forwardRef(function IconButton(props, ref) {
435
444
  target
436
445
  } = props,
437
446
  sharedProps = _objectWithoutPropertiesLoose(props, _excluded);
447
+ function handleKeyDown(e) {
448
+ const keyCode = e.key;
449
+ if (!href && (keyCode === "Enter" || keyCode === "Space")) {
450
+ e.preventDefault();
451
+ }
452
+ }
453
+ function handleKeyUp(e) {
454
+ const keyCode = e.key;
455
+ if (!href && (keyCode === "Enter" || keyCode === "Space")) {
456
+ if (sharedProps.onClick) {
457
+ sharedProps.onClick(e);
458
+ }
459
+ }
460
+ }
438
461
  return React.createElement(ThemedIconButton, null, React.createElement(IconButtonCore, _extends({}, sharedProps, {
439
462
  color: color,
440
463
  disabled: disabled,
@@ -445,7 +468,9 @@ const IconButton = React.forwardRef(function IconButton(props, ref) {
445
468
  skipClientNav: skipClientNav,
446
469
  size: size,
447
470
  target: target,
448
- tabIndex: tabIndex
471
+ tabIndex: tabIndex,
472
+ onKeyDown: handleKeyDown,
473
+ onKeyUp: handleKeyUp
449
474
  })));
450
475
  });
451
476
 
package/dist/index.js CHANGED
@@ -396,6 +396,15 @@ const _generateStyles = (buttonColor = "default", kind, light, size, theme, them
396
396
  borderRadius: theme.border.radius.default,
397
397
  outlineWidth: theme.border.width.default
398
398
  }, kindOverrides[":hover"]),
399
+ ["@media not (hover: hover)"]: {
400
+ ":hover": {
401
+ boxShadow: "none",
402
+ color: defaultColor,
403
+ borderRadius: theme.border.radius.default,
404
+ outline: "none",
405
+ backgroundColor: "transparent"
406
+ }
407
+ },
399
408
  ":focus": {
400
409
  boxShadow: `0 0 0 ${theme.border.width.default}px ${defaultStrokeColor}`,
401
410
  borderRadius: theme.border.radius.default
@@ -457,6 +466,20 @@ const IconButton = React__namespace.forwardRef(function IconButton(props, ref) {
457
466
  target
458
467
  } = props,
459
468
  sharedProps = _objectWithoutPropertiesLoose(props, _excluded);
469
+ function handleKeyDown(e) {
470
+ const keyCode = e.key;
471
+ if (!href && (keyCode === "Enter" || keyCode === "Space")) {
472
+ e.preventDefault();
473
+ }
474
+ }
475
+ function handleKeyUp(e) {
476
+ const keyCode = e.key;
477
+ if (!href && (keyCode === "Enter" || keyCode === "Space")) {
478
+ if (sharedProps.onClick) {
479
+ sharedProps.onClick(e);
480
+ }
481
+ }
482
+ }
460
483
  return React__namespace.createElement(ThemedIconButton, null, React__namespace.createElement(IconButtonCore, _extends({}, sharedProps, {
461
484
  color: color,
462
485
  disabled: disabled,
@@ -467,7 +490,9 @@ const IconButton = React__namespace.forwardRef(function IconButton(props, ref) {
467
490
  skipClientNav: skipClientNav,
468
491
  size: size,
469
492
  target: target,
470
- tabIndex: tabIndex
493
+ tabIndex: tabIndex,
494
+ onKeyDown: handleKeyDown,
495
+ onKeyUp: handleKeyUp
471
496
  })));
472
497
  });
473
498
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-icon-button",
3
- "version": "5.1.4",
3
+ "version": "5.1.6",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,7 +18,7 @@
18
18
  "@babel/runtime": "^7.18.6",
19
19
  "@khanacademy/wonder-blocks-clickable": "^4.0.11",
20
20
  "@khanacademy/wonder-blocks-core": "^6.3.0",
21
- "@khanacademy/wonder-blocks-icon": "^3.0.0",
21
+ "@khanacademy/wonder-blocks-icon": "^4.0.0",
22
22
  "@khanacademy/wonder-blocks-theming": "^1.2.1"
23
23
  },
24
24
  "peerDependencies": {