惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
G
Google Developers Blog
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
腾讯CDC
博客园_首页
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
博客园 - 叶小钗

Tailwind CSS Blog

Tailwind Labs is joining Shopify Tailwind CSS v4.3: Scrollbars, new colors, and more Vanilla JavaScript support for Tailwind Plus Vanilla JavaScript support for Tailwind Plus Compass: A starter kit for online courses Tailwind CSS v4.1: Text shadows, masks, and tons more Tailwind UI is now Tailwind Plus Tailwind UI is now Tailwind Plus Tailwind CSS v4.0 Tailwind CSS v4.0 Tailwind CSS v4.0 Beta 1 Tailwind CSS v4.0 Beta 1 Radiant: A beautiful new marketing site template Headless UI v2.1: Simplified transition API and improved multi-dialog support Automatically clean up whitespace and duplicate class names Automatically clean up whitespace and duplicate class names Catalyst: Application layouts, navigation menus, description lists, and more Headless UI v2.0 for React Headless UI v2.0 for React We're hiring a Design Engineer + Staff Engineer We're hiring a Design Engineer + Staff Engineer Open-sourcing our progress on Tailwind CSS v4.0 Open-sourcing our progress on Tailwind CSS v4.0 Introducing Catalyst: A modern UI kit for React Tailwind CSS v3.4: Dynamic viewport units, :has() support, balanced headlines, subgrid, and more Heroicons Micro: What are these, icons for ants? Meet Studio: Our beautiful new agency site template Tailwind Connect 2023: Recap of our first in-person event New changelog template + the biggest Tailwind UI update ever New changelog template + the biggest Tailwind UI update ever
Headless UI v1.4: The One With Tabs
2021-07-29 · via Tailwind CSS Blog

We just released Headless UI v1.4, which includes a brand new Tab component, and new APIs for manually closing Popover and Disclosure components more easily.

Tabs

Earlier this year we started working on Tailwind UI Ecommerce, and we realized pretty quickly we were going to need to support tabs in Headless UI to be able to build the new interfaces we were designing.

Here's what we ended up with:

import { Tab } from '@headlessui/react'function MyTabs() {  return (    <Tab.Group>      <Tab.List>        <Tab>Tab 1</Tab>        <Tab>Tab 2</Tab>        <Tab>Tab 3</Tab>      </Tab.List>      <Tab.Panels>        <Tab.Panel>Content 1</Tab.Panel>        <Tab.Panel>Content 2</Tab.Panel>        <Tab.Panel>Content 3</Tab.Panel>      </Tab.Panels>    </Tab.Group>  )}

And yep, those are tabs!

Like all Headless UI components, this totally abstracts away stuff like keyboard navigation for you so you can create custom tabs in a completely declarative way, without having to think about any of the tricky accessibility details.

Check out the documentation to learn more.

Closing disclosures and popovers

Up until now, there was no way to close a Disclosure without clicking the actual button used to open it. For typical disclosure use cases this isn't a big deal, but it often makes sense to use disclosures for things like mobile navigation, where you want to close it when someone clicks a link inside of it.

Now you can use Disclosure.Button or (DisclosureButton in Vue) within your disclosure panel to close the panel, making it easy to wrap up things like links or other buttons so the panel doesn't stay open:

import { Disclosure } from '@headlessui/react'import MyLink from './MyLink'function MyDisclosure() {  return (    <Disclosure>      <Disclosure.Button>Open mobile menu</Disclosure.Button>      <Disclosure.Panel>        <Disclosure.Button as={MyLink} href="/home">          Home        </Disclosure.Button>        {/* ... */}      </Disclosure.Panel>    </Disclosure>  )}

The same thing works with Popover components, too:

import { Popover } from '@headlessui/react'import MyLink from './MyLink'function MyPopover() {  return (    <Popover>      <Popover.Button>Solutions</Popover.Button>      <Popover.Panel>        <Popover.Button as={MyLink} href="/insights">          Insights        </Popover.Button>        {/* ... */}      </Popover.Panel>    </Popover>  )}

If you need finer control, we also pass a close function via the render prop/scoped slot, so you can imperatively close the panel when you need to:

import { Popover } from '@headlessui/react'function MyPopover() {  return (    <Popover>      <Popover.Button>Terms</Popover.Button>      <Popover.Panel>        {({ close }) => (          <button            onClick={async () => {              await fetch('/accept-terms', { method: 'POST' })              close()            }}          >            Read and accept          </button>        )}      </Popover.Panel>    </Popover>  )}

For more details, check out the updated Popover and Disclosure documentation.

Try it out

Headless UI v1.4 is a minor update so there are no breaking changes. To upgrade, just install the latest version via npm:

# For Reactnpm install @headlessui/react# For Vuenpm install @headlessui/vue

Check out the official website for the latest documentation, and check out Tailwind UI if you want to play with tons of styled examples.

Ready to try it out? Visit the Headless UI website →