Skip to content

Commit

Permalink
feat: use a native select element instead of @reach/listbox (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley committed Apr 27, 2023
1 parent 8a12329 commit 8d1faaa
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 181 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-pens-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-code-block': minor
---

Use a native select element instead of @reach/listbox
123 changes: 5 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/code-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"author": "HashiCorp",
"dependencies": {
"@hashicorp/react-inline-svg": "^6.0.3",
"@reach/listbox": "^0.17.0",
"shellwords": "^0.1.1"
},
"license": "MPL-2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/code-block/partials/code-tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function CodeTabs({
{hasOverflow ? (
<TabsAsDropdown
tabLabels={tabLabels}
activeTabIdx={activeTabIdx}
setActiveTabIdx={setActiveTabWithEvent}
hasHeading={hasHeading}
/>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

import classNames from 'classnames'
import s from './style.module.css'

interface TabsAsDropdownProps {
tabLabels: string[]
setActiveTabIdx: (tabIdx: number) => void
hasHeading: boolean
}

function TabsAsDropdown({
tabLabels,
setActiveTabIdx,
hasHeading,
}: TabsAsDropdownProps) {
return (
<div
className={classNames(s.tabsAsDropdown, { [s.hasHeading]: hasHeading })}
>
<select
className={s.listboxButton}
onChange={(e) => setActiveTabIdx(parseInt(e.target.value, 10))}
>
{tabLabels.map((tabLabel, idx) => (
<option key={tabLabel} value={idx}>
{tabLabel}
</option>
))}
</select>
</div>
)
}

export default TabsAsDropdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ to be present.
&.hasHeading {
margin-left: auto;
}

& option {
color: initial;
}
}

.listboxInput {
Expand All @@ -26,6 +30,8 @@ to be present.

.listboxButton {
composes: g-type-body-small-strong from global;
background-color: transparent;
border: 0;
color: var(--text-color-faded);
min-height: var(--base-height);
padding: 0 16px;
Expand Down

1 comment on commit 8d1faaa

@vercel
Copy link

@vercel vercel bot commented on 8d1faaa Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.