Skip to content

Commit

Permalink
Drop generateId support
Browse files Browse the repository at this point in the history
This never really worker for SSR applications because different ID is generated on server side than on client side. There are some ways to make it work properly but it looks too complicated. Let the user pass it down.

See more:
facebook/react#5867
  • Loading branch information
Joozty committed Aug 19, 2020
1 parent b689238 commit 7854d90
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/elements/forms/text-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control from './control'
import Addon from './addon'
import styles from './text-field.css'

import { classNames, generateId } from 'utils'
import { classNames } from 'utils'

/**
* Unique ID generator
Expand Down Expand Up @@ -44,7 +44,7 @@ const TextField = React.forwardRef(
(
{
children,
id = generateId(),
id,
className,
label,
helper,
Expand Down Expand Up @@ -117,10 +117,8 @@ TextField.propTypes = {
/**
* An ID that will be used to link input and label. It's necessary for
* accessibility.
*
* If not passed, it will be generated automatically using a random string.
*/
id: PropTypes.string,
id: PropTypes.string.isRequired,
/**
* Helper message to show bellow the input
*/
Expand Down
9 changes: 7 additions & 2 deletions src/modules/select/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { useInput, useOptions } from './hooks'
import styles from './select.css'

import { Form, Icon, Button } from 'elements'
import { classNames, generateId } from 'utils'
import { classNames } from 'utils'

const Select = React.memo(
({
id,
value,
onInput,
onChange,
Expand All @@ -21,7 +22,6 @@ const Select = React.memo(
clearButton = true,
clearOnFocus = false,
tag: Tag = 'div',
id = generateId(),
...restInputProps
}) => {
// custom select hooks
Expand Down Expand Up @@ -150,6 +150,11 @@ const Select = React.memo(
)

Select.propTypes = {
/**
* An ID that will be used to link input and label. It's necessary for
* accessibility.
*/
id: PropTypes.string.isRequired,
/* Label to show in input */
label: PropTypes.string.isRequired,
/* The current value shown in input field */
Expand Down
3 changes: 1 addition & 2 deletions src/modules/select/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const SelectExample = () => {
const [suggestions, setSuggestions] = React.useState(options)
const [value, setValue] = React.useState('Default option')
const [value, setValue] = React.useState('')

const handleOnChange = (data) => {
// trigger search here
Expand All @@ -36,7 +36,6 @@
id="select-1"
value={value}
label="Search"
variant="pure"
onChange={handleOnChange}
onInput={handleOnInput}
placeholder="e.g. article title or author name"
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * as classNames from './class-names'
export generateId from './unique-id'
3 changes: 0 additions & 3 deletions src/utils/unique-id.js

This file was deleted.

1 comment on commit 7854d90

@vercel
Copy link

@vercel vercel bot commented on 7854d90 Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.