Skip to content

feat(*): add way to get ref to focuable components#218

Merged
eddywashere merged 1 commit intoreactstrap:masterfrom
TheSharpieOne:feature/refs
Nov 1, 2016
Merged

feat(*): add way to get ref to focuable components#218
eddywashere merged 1 commit intoreactstrap:masterfrom
TheSharpieOne:feature/refs

Conversation

@TheSharpieOne
Copy link
Copy Markdown
Member

The main use-case for refs is the ability to set focus on an element, because of this, I have added the ability to get a ref to components which generate focusable items (inputs, buttons, links/anchor).

I just want to note, using a ref to get an input's value is not the correct way. Using a callback, such onChange or onBlur, you can use the supplied event to get the value without needing a ref.

@eddywashere
Copy link
Copy Markdown
Member

Could you add lodash noop as the default prop.

@TheSharpieOne
Copy link
Copy Markdown
Member Author

They default to undefined and when undefined is passed to ref, it is the same as not having a ref prop which I'd argue is probably better than triggering an extra function (even if the function does nothing).

@ajainarayanan
Copy link
Copy Markdown
Contributor

@TheSharpieOne I agree that refs could be used to set focus on an input element but wouldn't it be more straight forward by accepting a focus(or autoFocus) attribute for focus alone? We could also have a getRef attribute that will return the underlying input element's ref and can be used independently.

Its more of getting the element ref and focusing it vs setting the attribute of element and make itself focus.

@eddywashere
Copy link
Copy Markdown
Member

@TheSharpieOne great point. I didn't think about that. 👍

@ajainarayanan good discussion, moving this to #172 since it's out of scope for this pr.

@eddywashere eddywashere merged commit cbfa0e0 into reactstrap:master Nov 1, 2016
This was referenced Nov 1, 2016
eddywashere pushed a commit that referenced this pull request Nov 2, 2016
#216)

* add NavbarToggler example

* feat(Collapse): add Collapse component #79 (#201)

* init collapse

* add collapse animation

* add margin between toggle button and collapse

* disable lint on force refresh DOM line.

* add test to Collapse

* remove height after shown

* Revert "remove height after shown"

This reverts commit eff9353.

* remove height after shown.

* add more test

* use setState() to set inline height style

* remove custom tag in doc

* add inline style test

* remove comment

* set height to null when isOpen is true

* add initial state test

* chore(release): adding 3.8.0 (#217)

* chore(release): adding 3.8.0

* feat(Collapse): add cssModule support

* feat(refs): add getRef to focusable components (#218)

* chore(release): adding 3.8.1 (#219)

* add NavbarToggler example

* update example to use Collapse component
@TheSharpieOne TheSharpieOne deleted the feature/refs branch January 31, 2017 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants