Skip to content
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
2 changes: 1 addition & 1 deletion src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ButtonProps = React.HTMLAttributes<HTMLButtonElement> & {
*/
isLoading?: boolean;
/**
* a custom loding label
* a custom loading label
*/
loadingLabel?: string;
/**
Expand Down
8 changes: 8 additions & 0 deletions src/button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,12 @@ describe('Button', () => {
expect(buttons[2].getAttribute('aria-label')).toBe('submit-button');
expect(buttons[3].getAttribute('aria-label')).toBe('reset-button');
});

it('should accept tabIndex attribute', () => {
render(<Button label="X" tabIndex={1} />);

const button: any = screen.getByRole('button');

expect(button.getAttribute('tabindex')).toBe('1');
});
});
4 changes: 2 additions & 2 deletions src/copyToClipboard/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type CopyToClipboardProps = Omit<
export const CopyToClipboard = React.forwardRef<
HTMLElement,
CopyToClipboardProps
>(({ icon, onCopy, text, children, ...props }, ref) => {
>(({ icon, onCopy, text, children, tabIndex = 0, ...props }, ref) => {
const onClickHandler = () => {
const inputRef = ref as MutableRefObject<HTMLElement>;
document.execCommand('copy');
Expand All @@ -24,7 +24,7 @@ export const CopyToClipboard = React.forwardRef<
);
};
return (
<button onClick={onClickHandler} {...props}>
<button onClick={onClickHandler} {...props} tabIndex={tabIndex}>
{icon}
{children}
</button>
Expand Down
28 changes: 28 additions & 0 deletions src/copyToClipboard/__test__/CopyToClipboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,32 @@ describe('CopyToClipboard', () => {
const copiedValue = screen.getByTestId('copied');
expect(copiedValue.innerHTML).toBe('helloWorld');
});

it('should have 0 tabIndex value by default', () => {
const onCopyHandler = jest.fn();

render(
<CopyToClipboard onCopy={onCopyHandler}>
<div>custom</div>
</CopyToClipboard>
);

const button: any = screen.getByRole('button');

expect(button.getAttribute('tabindex')).toBe('0');
});

it('should accept tabIndex attribute', () => {
const onCopyHandler = jest.fn();

render(
<CopyToClipboard tabIndex={1} onCopy={onCopyHandler}>
<div>custom</div>
</CopyToClipboard>
);

const button: any = screen.getByRole('button');

expect(button.getAttribute('tabindex')).toBe('1');
});
});
11 changes: 10 additions & 1 deletion src/details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type DetailsProps = {
* summary text class name
*/
summaryTextClassName?: string;
/**
* details tab index
*/
tabIndex?: number;
};

const OPEN: string = 'open';
Expand All @@ -46,6 +50,7 @@ export const Details = ({
openClassName,
summaryClassName,
summaryTextClassName,
tabIndex = 0,
}: DetailsProps) => {
const [isOpen, setIsOpen] = useState<boolean>(open);

Expand All @@ -55,7 +60,11 @@ export const Details = ({

return (
<details className={detailsClassName} open={open}>
<summary className={summaryClassName} onClick={handleOnChange}>
<summary
className={summaryClassName}
onClick={handleOnChange}
tabIndex={tabIndex}
>
<span className={summaryTextClassName}>{summary}</span>
</summary>
<div
Expand Down
28 changes: 28 additions & 0 deletions src/details/__test__/Details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,32 @@ describe('Details', () => {
);
expect(container.querySelector('.details-text-class-name.open')).toBeNull();
});

it('should have 0 tabIndex value by default', () => {
const { container } = render(
<Details summary="my summary" summaryClassName="summary-class-name">
my details
</Details>
);

const summary: any = container.querySelector('.summary-class-name');

expect(summary.getAttribute('tabindex')).toBe('0');
});

it('should accept tabIndex attribute', () => {
const { container } = render(
<Details
summary="my summary"
summaryClassName="summary-class-name"
tabIndex={1}
>
my details
</Details>
);

const summary: any = container.querySelector('.summary-class-name');

expect(summary.getAttribute('tabindex')).toBe('1');
});
});
3 changes: 3 additions & 0 deletions src/formDate/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DateProps = DateType & {
disabled?: boolean;
maxLength?: number;
handleChange: (evt: React.FormEvent<HTMLInputElement>) => void;
tabIndex?: number;
};

export const DateComponent = ({
Expand All @@ -22,6 +23,7 @@ export const DateComponent = ({
classNameInput,
disabled,
maxLength = 2,
tabIndex = 0,
}: DateProps) => (
<label
style={{ display: 'flex', flexDirection: 'column' }}
Expand All @@ -41,6 +43,7 @@ export const DateComponent = ({
inputMode="numeric"
maxLength={maxLength}
pattern="[0-9]*"
tabIndex={tabIndex}
/>
</label>
);
10 changes: 10 additions & 0 deletions src/formDate/FormDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type DateType = {
classNameLabel?: string;
classNameSpan?: string;
customLabel?: JSX.Element;
tabIndex?: number;
};

type ErrorPosition = 'top' | 'bottom';
Expand Down Expand Up @@ -51,6 +52,8 @@ type FormDateProps = {
* classNameSpan?: string;
* // if you want to pass a custom Label (i.e. an h1 etc)
* customLabel?: JSX.Element;
* // if you want to pass tab index for the input
* tabIndex?: number;
*/
yearProps?: DateType;
/**
Expand All @@ -65,6 +68,8 @@ type FormDateProps = {
* classNameSpan?: string;
* // if you want to pass a custom Label (i.e. an h1 etc)
* customLabel?: JSX.Element;
* // if you want to pass tab index for the input
* tabIndex?: number;
*/
monthProps?: DateType;
/**
Expand All @@ -79,6 +84,8 @@ type FormDateProps = {
* classNameSpan?: string;
* // if you want to pass a custom Label (i.e. an h1 etc)
* customLabel?: JSX.Element;
* // if you want to pass tab index for the input
* tabIndex?: number;
*/
dayProps?: DateType;

Expand Down Expand Up @@ -217,6 +224,7 @@ export const FormDate = ({
label={yearProps?.label}
classNameInput={[yearProps?.classNameInput, inputClass].join(' ')}
disabled={disabled}
tabIndex={yearProps?.tabIndex}
/>
);
case 'm':
Expand All @@ -233,6 +241,7 @@ export const FormDate = ({
label={monthProps?.label}
classNameInput={[monthProps?.classNameInput, inputClass].join(' ')}
disabled={disabled}
tabIndex={monthProps?.tabIndex}
/>
);
case 'd':
Expand All @@ -249,6 +258,7 @@ export const FormDate = ({
label={dayProps?.label}
classNameInput={[dayProps?.classNameInput, inputClass].join(' ')}
disabled={disabled}
tabIndex={dayProps?.tabIndex}
/>
);
default:
Expand Down
34 changes: 34 additions & 0 deletions src/formDate/__test__/FormDate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,38 @@ describe('FormInput', () => {
expect(input[1].innerHTML).toBe('');
expect(input[2].innerHTML).toBe('');
});

it('should accept tabIndex attribute for year and month and day inputs', () => {
const { container } = render(
<FormDate
dateFormat="dd/mm/yyyy"
handleValidity={jest.fn()}
yearProps={{ label: 'Year', tabIndex: 0 }}
monthProps={{ label: 'Month', tabIndex: 1 }}
dayProps={{ label: 'Day', tabIndex: 0 }}
/>
);

const inputField: any = container.querySelectorAll('input');
expect(inputField[0].getAttribute('tabindex')).toBe('0');
expect(inputField[1].getAttribute('tabindex')).toBe('1');
expect(inputField[2].getAttribute('tabindex')).toBe('0');
});

it('should have 0 tabIndex value for the inputs by default', () => {
const { container } = render(
<FormDate
dateFormat="dd/mm/yyyy"
handleValidity={jest.fn()}
yearProps={{ label: 'Year' }}
monthProps={{ label: 'Month' }}
dayProps={{ label: 'Day' }}
/>
);

const inputField: any = container.querySelectorAll('input');
expect(inputField[0].getAttribute('tabindex')).toBe('0');
expect(inputField[1].getAttribute('tabindex')).toBe('0');
expect(inputField[2].getAttribute('tabindex')).toBe('0');
});
});
1 change: 1 addition & 0 deletions stories/Details/Documentation.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ An example with all the available properties is:
summaryClassName="summary-class-name"
summaryTextClassName="summar-text-class-name"
open={true}
tabIndex={0}
>
my-detail
</Details>
Expand Down
3 changes: 3 additions & 0 deletions stories/FormDate/Documentation.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,22 @@ return (
customLabel: <CustomComponent>Year</CustomComponent>, //you can specify your customLabel component
classNameLabel: 'yearLabel',
classNameSpan: 'span',
tabIndex: 1,
}}
monthProps={{
label: 'Month',
classNameInput: 'classInput',
classNameLabel: 'monthLabel',
classNameSpan: 'classSpan',
tabIndex: 0,
}}
dayProps={{
classNameLabel: 'dayLabel',
label: 'Day',
classNameInput: 'classInput',
classNameLabel: 'classDayLabel',
classNameSpan: 'classSpan',
tabIndex: 0,
}}
day="29"
month="07"
Expand Down
2 changes: 1 addition & 1 deletion stories/liveEdit/DetailsLive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Details } from '../../src/details/Details';
const DetailsDemo = `
function DetailsDemo() {
return (
<Details summary="headline summary">some details</Details>
<Details summary="headline summary" tabIndex={0}>some details</Details>
)
}
`.trim();
Expand Down
9 changes: 6 additions & 3 deletions stories/liveEdit/FormDateLive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ function FormDateDemo() {
classNameInput: "",
classNameLabel: "",
classNameSpan: "",
customLabel: <></>
customLabel: <></>,
tabIndex: 0
}}
monthProps={{
label: "",
classNameInput: "",
classNameLabel: "",
classNameSpan: "",
customLabel: <></>
customLabel: <></>,
tabIndex: 0
}}
dayProps={{
label: "",
classNameInput: "",
classNameLabel: "",
classNameSpan: "",
customLabel: <></>
customLabel: <></>,
tabIndex: 0
}}
displayError={false}
errorMessage=""
Expand Down