Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds feature to input custom contentId to address issue #217. #218

Merged
merged 5 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ Disables the trigger handler if `true`. Note: this has no effect other than appl

Pass props (or attributes) to the trigger wrapping element. Useful for inserting `role` when using `tabIndex`.

As an alternative to an auto generated id (which is not guaranteed to be unique in extremely fast builds) that is used as the TriggerElement id, and also as a separate `aria-labelledby` attribute, a custom id can be assigned by providing `triggerElementProps` with an object containing an `id` key and value, e.g. `{id: 'some-value'}`.

### **contentElementId** | _string_

Allows for an alternative to an auto generated id (which is not guaranteed to be unique in extremely fast builds) that is used as part of the component id and the `aria-controls` attribute of the component.

### **transitionTime** | _number_ | default: 400

The number of milliseconds for the open/close transition to take.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CollapsibleProps extends React.HTMLProps<Collapsible> {
triggerClassName?: string;
triggerOpenedClassName?: string;
triggerElementProps?: object;
contentElementId?: string;
contentOuterClassName?: string;
contentInnerClassName?: string;
accordionPosition?: string | number;
Expand Down
3 changes: 2 additions & 1 deletion src/Collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Collapsible extends Component {

this.timeout = undefined;

this.contentId = `collapsible-content-${Date.now()}`;
this.contentId = props.contentElementId || `collapsible-content-${Date.now()}`;
nathanhere marked this conversation as resolved.
Show resolved Hide resolved
this.triggerId = props.triggerElementProps.id || `collapsible-trigger-${Date.now()}`;

// Defaults the dropdown to be closed
Expand Down Expand Up @@ -285,6 +285,7 @@ Collapsible.propTypes = {
open: PropTypes.bool,
containerElementProps: PropTypes.object,
triggerElementProps: PropTypes.object,
contentElementId: PropTypes.string,
classParentString: PropTypes.string,
className: PropTypes.string,
openedClassName: PropTypes.string,
Expand Down