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

fix: rename floating inputs to inset #880

Merged
merged 3 commits into from
Mar 7, 2024
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
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { useState } from 'react';
import { action } from '@storybook/addon-actions';
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { SelectInputNativeFloating } from './SelectInputNativeFloating';
import { SelectInputNativeInset } from './SelectInputNativeInset';
import { RESPONSIVE_STORY } from '../../docs/constants';
import { Box } from '../Box/Box';
import { Icon } from '../Icon/Icon';

<Meta
title="Components/SelectInputNativeFloating/Overview"
component={SelectInputNativeFloating}
title="Components/SelectInputNativeInset/Overview"
component={SelectInputNativeInset}
parameters={{
controls: { hideNoControlsWarning: true },
}}
/>

# SelectInputNativeFloating
# SelectInputNativeInset

Use `SelectInputNativeFloating` to create a floating label input field, but unlike `TextInputFloating` they always show the `label` in the floated state. It is a controlled component, which means that you need to provide a value and an `onChange` handler to update the value.
Use `SelectInputNativeInset` to create a floating label input field, but unlike `TextInputInset` they always show the `label` in the floated state. It is a controlled component, which means that you need to provide a value and an `onChange` handler to update the value.

<Canvas withSource="open">
<Story
Expand All @@ -36,7 +36,7 @@ Use `SelectInputNativeFloating` to create a floating label input field, but unli
{ value: 'vanilla', label: 'Vanilla' },
];
return (
<SelectInputNativeFloating
<SelectInputNativeInset
id="default Select"
label="Label"
onChange={event => {
Expand All @@ -52,7 +52,7 @@ Use `SelectInputNativeFloating` to create a floating label input field, but unli

## Props

<ArgsTable of={SelectInputNativeFloating} />
<ArgsTable of={SelectInputNativeInset} />

### Required

Expand All @@ -69,7 +69,7 @@ Use the `isRequired` prop to display an `*` after the label and set the `require
];
return (
<Box gap="md">
<SelectInputNativeFloating
<SelectInputNativeInset
id="requiredSelect"
label="Required Field"
onChange={event => {
Expand All @@ -79,7 +79,7 @@ Use the `isRequired` prop to display an `*` after the label and set the `require
value={value}
isRequired
/>
<SelectInputNativeFloating
<SelectInputNativeInset
id="customRequiredSelect"
label="Custom Required Indicator Field"
onChange={event => {
Expand Down Expand Up @@ -110,7 +110,7 @@ Use `helpText` to provide additional information about the input field.
{ value: 'Tesla', label: 'Tesla' },
];
return (
<SelectInputNativeFloating
<SelectInputNativeInset
id="helpTextSelect"
label="Inverter Manufacturer"
helpText="Must be from the approved vendor list"
Expand Down Expand Up @@ -139,7 +139,7 @@ Use the `error` prop to mark the input as invalid. `error` accepts a `boolean`,
{ value: 'Tesla', label: 'Tesla' },
];
return (
<SelectInputNativeFloating
<SelectInputNativeInset
id="errorSelect"
label="Inverter Manufacturer"
helpText="Must be from the approved vendor list"
Expand Down Expand Up @@ -169,7 +169,7 @@ Add `isDisabled`to give it a grayed out appearance, remove pointer events, and p
{ value: 'Tesla', label: 'Tesla' },
];
return (
<SelectInputNativeFloating
<SelectInputNativeInset
id="disabledSelect"
label="Disabled Input"
onChange={event => {
Expand Down Expand Up @@ -199,7 +199,7 @@ a callback function when the clear icon is clicked, which can then be handled to
{ value: 'option3', label: 'Option 3' },
];
return (
<SelectInputNativeFloating
<SelectInputNativeInset
id="clearableSelect"
label="Clearable Input"
onChange={event => {
Expand Down Expand Up @@ -229,22 +229,22 @@ Two sizes, `md` and `lg` are available, with `md` being the default.
];
return (
<Box gap="md">
<SelectInputNativeFloating
<SelectInputNativeInset
id="mdFlavorInput"
value={value}
label="md size"
onChange={event => setValue(event.target.value)}
options={options}
/>
<SelectInputNativeFloating
<SelectInputNativeInset
id="lgFlavorInput"
value={value}
size="lg"
label="lg size"
onChange={event => setValue(event.target.value)}
options={options}
/>
<SelectInputNativeFloating
<SelectInputNativeInset
id="responsiveFlavorInput"
value={value}
size={{ base: 'md', tablet: 'lg', desktop: 'md', hd: 'lg' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import { Meta, Story } from '@storybook/react/types-6-0';
import { boxPropsKeys } from '../Box/Box';
import {
SelectInputNativeFloating,
SelectInputNativeFloatingProps,
} from './SelectInputNativeFloating';
SelectInputNativeInset,
SelectInputNativeInsetProps,
} from './SelectInputNativeInset';

export default {
title: 'Components/SelectInputNativeFloating/Playground',
component: SelectInputNativeFloating,
title: 'Components/SelectInputNativeInset/Playground',
component: SelectInputNativeInset,
argTypes: {
id: {
control: 'text',
Expand Down Expand Up @@ -62,15 +62,15 @@ export default {
},
} as Meta;

const Template: Story<SelectInputNativeFloatingProps> = ({ ...args }) => (
<SelectInputNativeFloating {...args} />
const Template: Story<SelectInputNativeInsetProps> = ({ ...args }) => (
<SelectInputNativeInset {...args} />
);

export const Playground = Template.bind({});
Playground.args = {
id: 'playgroundSelectInputNativeFloating',
label: 'Playground SelectInputNativeFloating',
name: 'playgroundSelectInputNativeFloating',
id: 'playgroundSelectInputNativeInset',
label: 'Playground SelectInputNativeInset',
name: 'playgroundSelectInputNativeInset',
options: [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import { BreakpointSize } from '../../types';
import { SelectInputNativeFloating } from './SelectInputNativeFloating';
import { SelectInputNativeInset } from './SelectInputNativeInset';

const selectOptions = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' },
];

describe('SelectInputNativeFloating', () => {
describe('SelectInputNativeInset', () => {
describe('Callback Handling', () => {
test('it fires onChange callback on change', async () => {
const mockedHandleChange = jest.fn();

const { getByLabelText } = render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
placeholder="Test Placeholder"
Expand All @@ -35,7 +35,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleFocus = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
onFocus={mockedHandleFocus}
Expand All @@ -56,7 +56,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleBlur = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
onBlur={mockedHandleBlur}
Expand All @@ -78,7 +78,7 @@ describe('SelectInputNativeFloating', () => {
test('onClear prop renders clear icon when input has value', () => {
const mockedHandleChange = jest.fn();
render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
options={selectOptions}
Expand All @@ -96,7 +96,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleClear = jest.fn(() => null);

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
options={selectOptions}
Expand All @@ -123,7 +123,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleChange = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
label="Select Label"
Expand All @@ -138,7 +138,7 @@ describe('SelectInputNativeFloating', () => {

test('assigns the "aria-labelledby" attribute and renders label correct id, when a label is provided', () => {
render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testInput"
label="test label"
options={selectOptions}
Expand All @@ -160,7 +160,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleChange = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
label="Required Select"
Expand All @@ -179,7 +179,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleChange = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
label="Select Label"
Expand All @@ -198,7 +198,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleChange = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
label="disabled test"
Expand All @@ -217,7 +217,7 @@ describe('SelectInputNativeFloating', () => {
const mockedHandleChange = jest.fn();

render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
label="Select Label"
Expand All @@ -241,7 +241,7 @@ describe('SelectInputNativeFloating', () => {
sizes.forEach(size => {
test(`it has a ${size} class applied to it`, () => {
render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
options={selectOptions}
Expand All @@ -258,7 +258,7 @@ describe('SelectInputNativeFloating', () => {
breakpoints.forEach(breakpoint => {
test(`it applies responsive classes for breakpoint: ${breakpoint} and size: ${size}`, () => {
render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
options={selectOptions}
Expand All @@ -279,7 +279,7 @@ describe('SelectInputNativeFloating', () => {

test('It applies responsive classes when multiple are applied', () => {
render(
<SelectInputNativeFloating
<SelectInputNativeInset
id="testId"
onChange={mockedHandleChange}
options={selectOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import { HelpText } from '../HelpText/HelpText';
import { Icon } from '../Icon/Icon';
import { getAutoCompleteValue } from '../../lib/getAutoCompleteValue';
import styles from './SelectInputNativeFloating.module.scss';
import styles from './SelectInputNativeInset.module.scss';
import { InputValidationMessage } from '../InputValidationMessage/InputValidationMessage';

export type SelectInputNativeFloatingSize = 'md' | 'lg';
export interface SelectInputNativeFloatingProps {
export type SelectInputNativeInsetSize = 'md' | 'lg';
export interface SelectInputNativeInsetProps {
/**
* The input's id attribute. Used to programmatically tie the input with its label.
*/
Expand Down Expand Up @@ -104,15 +104,15 @@
* The size of the text input.
*/
size?:
| SelectInputNativeFloatingSize
| ResponsiveProp<SelectInputNativeFloatingSize>;
| SelectInputNativeInsetSize
| ResponsiveProp<SelectInputNativeInsetSize>;
/**
* Additional props to be spread to rendered element
*/
[x: string]: any; // eslint-disable-line
}

export const SelectInputNativeFloating: ForwardRefExoticComponent<SelectInputNativeFloatingProps> = forwardRef<HTMLDivElement, SelectInputNativeFloatingProps>(
export const SelectInputNativeInset: ForwardRefExoticComponent<SelectInputNativeInsetProps> = forwardRef<HTMLDivElement, SelectInputNativeInsetProps>(

Check warning on line 115 in src/components/SelectInputNativeInset/SelectInputNativeInset.tsx

View workflow job for this annotation

GitHub Actions / lint js

This line has a length of 150. Maximum allowed is 120
(
{
id,
Expand Down Expand Up @@ -176,7 +176,7 @@
);
};

const computedInputProps: SelectInputNativeFloatingProps['inputProps'] = {
const computedInputProps: SelectInputNativeInsetProps['inputProps'] = {
...inputProps, // These are spread first so that we don't have top level props overwritten by the user.
'aria-required': isRequired,
'aria-invalid': !!error,
Expand Down
Loading
Loading