playbook_ui 14.25.0.pre.alpha.PLAY2413togglefocusstate9860 → 14.25.0.pre.alpha.PLAY2413togglefocusstate9920

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3677879da7e593e31525255b55b5237409162518114a48b5831e32c1180590a0
4
- data.tar.gz: 4dc0cdad6ff5ab48b0a4ecd6679dc64b03f80552fb8a41ab770484ec6cc4a59b
3
+ metadata.gz: '08c5fafb74ac67e1633ca73e3cd435d8990e29908bae3fa569c6235c52640c58'
4
+ data.tar.gz: ded16b9d9f16fdfce8c21c80c5a6266783dfe5e1343a06ae1b465e1086eed059
5
5
  SHA512:
6
- metadata.gz: aaa29afaa3704156fdc575ca96dbe0b1352ec51efe1782d6614c488a74cffafea43cb11891ff647c6d6f6cfa631cd6a8d5d9168e571710ae4dd8a86abd4e6cb0
7
- data.tar.gz: cc0eb00716a6d0095082da70b28c6bdc1089987b71822f603c909b46b8c3569d80a7a61294af65b4792da0eba762a2baa57aba99b3a24080d1a801859ba07f02
6
+ metadata.gz: aab9fa7145f8d46552d5a0320d50efd33df12c93a993a69c75bb21f2c443bc0b35af97962e691c72a7c24dea8ef47f1df77b4272a03f8417d8ff76cb73092ca6
7
+ data.tar.gz: fd23cd05afe95eb13f5857fb789a49a7f17f3cd79fe4eb0fc557657044d0208695407bf9dbb628a960ea1f05752ddbd7906b2df0189d05c51255a08d35b8cdba
@@ -1,6 +1,7 @@
1
- import React from 'react'
1
+ import React, { useState } from 'react'
2
2
  import classnames from 'classnames'
3
3
  import type { InputCallback } from '../types'
4
+ import { uniqueId } from '../utilities/object'
4
5
 
5
6
  import {
6
7
  buildAriaProps,
@@ -57,6 +58,9 @@ const Toggle = ({
57
58
  }
58
59
  ))
59
60
 
61
+ const [autoId] = useState(() => uniqueId('toggle-'))
62
+ const inputId = id ? `${id}-input` : `${autoId}-input`
63
+
60
64
  return (
61
65
  <div
62
66
  {...ariaProps}
@@ -65,7 +69,9 @@ const Toggle = ({
65
69
  className={classnames(css, globalProps(props), className)}
66
70
  id={id}
67
71
  >
68
- <label className="pb_toggle_wrapper">
72
+ <label className="pb_toggle_wrapper"
73
+ htmlFor={inputId}
74
+ >
69
75
  {children && children}
70
76
 
71
77
  {!children &&
@@ -73,6 +79,7 @@ const Toggle = ({
73
79
  {...props}
74
80
  defaultChecked={checked}
75
81
  disabled={disabled}
82
+ id={inputId}
76
83
  name={name}
77
84
  onChange={onChange}
78
85
  tabIndex={tabIndex}
@@ -1,5 +1,5 @@
1
1
  <%= pb_content_tag do %>
2
- <label class="pb_toggle_wrapper">
2
+ <label class="pb_toggle_wrapper" for="<%= object.id %>-input">
3
3
  <%= content.presence || object.input %>
4
4
  <div class="pb_toggle_control"></div>
5
5
  </label>
@@ -22,7 +22,8 @@ module Playbook
22
22
  end
23
23
 
24
24
  def input
25
- check_box_tag(name, value, checked, input_options.merge(disabled: disabled))
25
+ input_id = id.present? ? "#{id}-input" : "pb_toggle_#{SecureRandom.hex(4)}"
26
+ check_box_tag(name, value, checked, input_options.merge(disabled: disabled, id: input_id))
26
27
  end
27
28
 
28
29
  private