Skip to content

Commit

Permalink
Merge branch 'master' into 5815-warning-inner-fill-progress-indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored Apr 7, 2020
2 parents 64e0804 + 87ad959 commit 85b4469
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -18889,8 +18889,9 @@ List box styles
position: absolute;
top: 0;
right: $carbon--spacing-05;
bottom: 0;
height: 100%;
display: flex;
align-items: center;
transition: transform $duration--fast-01 motion(standard, productive);
cursor: pointer;
}
Expand Down Expand Up @@ -19195,6 +19196,25 @@ List box styles
overflow: hidden;
}

// Dropdown top orientation modifiers
.#{$prefix}--list-box--up .#{$prefix}--list-box__menu {
bottom: 2.5rem;
}

.#{$prefix}--list-box--up.#{$prefix}--dropdown--sm
.#{$prefix}--list-box__menu,
.#{$prefix}--list-box--up.#{$prefix}--list-box--sm
.#{$prefix}--list-box__menu {
bottom: 2rem;
}

.#{$prefix}--list-box--up.#{$prefix}--dropdown--xl
.#{$prefix}--list-box__menu,
.#{$prefix}--list-box--up.#{$prefix}--list-box--xl
.#{$prefix}--list-box__menu {
bottom: 3rem;
}

// Tweaks for descendants
// When handling input, we need to target nodes that specifically opt-in to
// the `combobox` role in order to make sure the text input is styled
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/components/Accordion/AccordionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { match, keys } from '../../internal/keyboard';
import { useId } from '../../internal/useId';

const { prefix } = settings;
const defaultRenderExpando = props => <button {...props} />;
Expand All @@ -28,6 +29,7 @@ function AccordionItem({
const [isOpen, setIsOpen] = useState(open);
const [prevIsOpen, setPrevIsOpen] = useState(open);
const [animation, setAnimation] = useState('');
const id = useId('accordion-item');
const className = cx({
[`${prefix}--accordion__item`]: true,
[`${prefix}--accordion__item--active`]: isOpen,
Expand Down Expand Up @@ -70,6 +72,7 @@ function AccordionItem({
return (
<li className={className} {...rest} onAnimationEnd={handleAnimationEnd}>
<Expando
aria-controls={id}
aria-expanded={isOpen}
className={`${prefix}--accordion__heading`}
onClick={onClick}
Expand All @@ -82,7 +85,9 @@ function AccordionItem({
/>
<div className={`${prefix}--accordion__title`}>{title}</div>
</Expando>
<div className={`${prefix}--accordion__content`}>{children}</div>
<div id={id} className={`${prefix}--accordion__content`}>
{children}
</div>
</li>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`Accordion should render 1`] = `
onAnimationEnd={[Function]}
>
<defaultRenderExpando
aria-controls="accordion-item-1"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand All @@ -25,6 +26,7 @@ exports[`Accordion should render 1`] = `
type="button"
>
<button
aria-controls="accordion-item-1"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand Down Expand Up @@ -71,6 +73,7 @@ exports[`Accordion should render 1`] = `
</defaultRenderExpando>
<div
className="bx--accordion__content"
id="accordion-item-1"
>
Panel A
</div>
Expand All @@ -85,6 +88,7 @@ exports[`Accordion should render 1`] = `
onAnimationEnd={[Function]}
>
<defaultRenderExpando
aria-controls="accordion-item-2"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand All @@ -93,6 +97,7 @@ exports[`Accordion should render 1`] = `
type="button"
>
<button
aria-controls="accordion-item-2"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand Down Expand Up @@ -139,6 +144,7 @@ exports[`Accordion should render 1`] = `
</defaultRenderExpando>
<div
className="bx--accordion__content"
id="accordion-item-2"
>
Panel B
</div>
Expand All @@ -153,6 +159,7 @@ exports[`Accordion should render 1`] = `
onAnimationEnd={[Function]}
>
<defaultRenderExpando
aria-controls="accordion-item-3"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand All @@ -161,6 +168,7 @@ exports[`Accordion should render 1`] = `
type="button"
>
<button
aria-controls="accordion-item-3"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand Down Expand Up @@ -207,6 +215,7 @@ exports[`Accordion should render 1`] = `
</defaultRenderExpando>
<div
className="bx--accordion__content"
id="accordion-item-3"
>
Panel C
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`AccordionItem should render 1`] = `
onAnimationEnd={[Function]}
>
<defaultRenderExpando
aria-controls="accordion-item-1"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand All @@ -18,6 +19,7 @@ exports[`AccordionItem should render 1`] = `
type="button"
>
<button
aria-controls="accordion-item-1"
aria-expanded={false}
className="bx--accordion__heading"
onClick={[Function]}
Expand Down Expand Up @@ -64,6 +66,7 @@ exports[`AccordionItem should render 1`] = `
</defaultRenderExpando>
<div
className="bx--accordion__content"
id="accordion-item-1"
>
Lorem ipsum.
</div>
Expand Down
32 changes: 32 additions & 0 deletions packages/react/src/internal/__tests__/useId-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright IBM Corp. 2020
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { render, cleanup } from '@carbon/test-utils/react';
import React from 'react';
import { useId } from '../useId';

describe('useId', () => {
afterEach(cleanup);

it('should generate a unique id that is stable across renders', () => {
function Test() {
const id = useId('test');
return <span id={id}>test</span>;
}

const container = document.createElement('div');
const getTestId = () => container.firstChild.getAttribute('id');

render(<Test />, { container });

const id = getTestId();
expect(getTestId()).toBeDefined();

render(<Test />, { container });
expect(id).toBe(getTestId());
});
});
21 changes: 21 additions & 0 deletions packages/react/src/internal/useId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { useRef } from 'react';
import setupGetInstanceId from '../tools/setupGetInstanceId';

const getId = setupGetInstanceId();

/**
* Generate a unique ID with an optional prefix prepended to it
* @param {string} [prefix]
* @returns {string}
*/
export function useId(prefix = 'id') {
const ref = useRef(`${prefix}-${getId()}`);
return ref.current;
}

0 comments on commit 85b4469

Please sign in to comment.