Skip to content

Commit

Permalink
Add story + sandbox example for floating labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgio committed Jun 3, 2022
1 parent 40668ba commit 3b93a26
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ You can also try out the following sandbox examples:
- [Custom loader & clear button](https://codesandbox.io/s/rbt-custom-aux-components-gn3kn)
- [Multi-select with reorderable drag & drop tokens](https://codesandbox.io/s/rbt-drag-drop-token-example-u43sf)
- [Keep the menu open during multi-selection](https://codesandbox.io/s/rbt-keep-menu-open-during-multi-select-nr2y4)
- [Single-select with floating label (BS5)](https://codesandbox.io/s/rbt-floating-labels-8c2j6b)

If you have an example use case that would be useful to others, please create a sandbox and submit a pull request to add it to the list!

Expand Down
22 changes: 22 additions & 0 deletions src/components/Typeahead/Typeahead.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useState } from 'react';
import { Story, Meta } from '@storybook/react';

import Typeahead, { TypeaheadComponentProps } from './Typeahead';
import Hint from '../Hint';
import Menu from '../Menu';
import MenuItem from '../MenuItem';

Expand Down Expand Up @@ -94,6 +95,27 @@ AllowNew.args = {
allowNew: true,
};

export const CustomInput = Template.bind({});
CustomInput.args = {
...defaultProps,
renderInput: ({ inputRef, referenceElementRef, ...inputProps }) => (
<Hint>
<div className="form-floating">
<input
{...inputProps}
className="form-control"
id="floatingInput"
ref={(node) => {
inputRef(node);
referenceElementRef(node);
}}
/>
<label htmlFor="floatingInput">{inputProps.placeholder}</label>
</div>
</Hint>
),
};

export const CustomMenu = Template.bind({});
CustomMenu.args = {
...defaultProps,
Expand Down
71 changes: 71 additions & 0 deletions src/components/Typeahead/__snapshots__/Typeahead.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,77 @@ exports[`<Typeahead> Controlled story renders snapshot 1`] = `
</div>
`;
exports[`<Typeahead> CustomInput story renders snapshot 1`] = `
<div
className="rbt"
style={
Object {
"outline": "none",
"position": "relative",
}
}
tabIndex={-1}
>
<div
style={
Object {
"display": "flex",
"flex": 1,
"height": "100%",
"position": "relative",
}
}
>
<div
className="form-floating"
>
<input
aria-autocomplete="both"
aria-expanded={false}
aria-haspopup="listbox"
autoComplete="off"
className="form-control"
id="floatingInput"
onBlur={[Function]}
onChange={[Function]}
onClick={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
placeholder="Choose a state..."
role="combobox"
type="text"
value=""
/>
<label
htmlFor="floatingInput"
>
Choose a state...
</label>
</div>
<input
aria-hidden={true}
className="rbt-input-hint"
readOnly={true}
style={
Object {
"backgroundColor": "transparent",
"borderColor": "transparent",
"boxShadow": "none",
"color": "rgba(0, 0, 0, 0.54)",
"left": 0,
"pointerEvents": "none",
"position": "absolute",
"top": 0,
"width": "100%",
}
}
tabIndex={-1}
value=""
/>
</div>
</div>
`;
exports[`<Typeahead> CustomMenu story renders snapshot 1`] = `
<div
className="rbt"
Expand Down

0 comments on commit 3b93a26

Please sign in to comment.