Mastering Fluent UI Web: Adjusting the border radius of a TextField component

I am in the process of creating a custom user input control that includes a TextField, a Dropdown, and a Button.

To ensure that the TextField and Dropdown appear as a cohesive unit rather than two separate elements, I attempted to use two specific styles (borderTopLeftRadius and borderBottomLeftRadiustried) on the TextField to eliminate its rounded corners. Unfortunately, this approach did not yield the desired results.

https://i.sstatic.net/L8VnQ.png

This is the desired outcome I am aiming for: https://i.sstatic.net/JKyKz.png

Below is the relevant TypeScript code snippet:

import React from 'react';
import { Stack, Text, Link, Dropdown, IDropdownStyles, ITextFieldStyleProps, IStackTokens, IStackStyles, ITextStyles, IDropdownOption, DropdownMenuItemType, PrimaryButton, TextField, initializeIcons, ITextFieldStyles } from '@fluentui/react';

const optionsFilterType: IDropdownOption[] = [
  { key: 'opt0', text: 'A', data: '11'},
  { key: 'opt1', text: 'B', data: '22' },
  { key: 'opt2', text: 'C', data: '33' },
];

<Stack horizontal>
  <TextField className="TTTT"
     style={{borderTopRightRadius: 0, borderBottomRightRadius: 0}}
     placeholder="---------Text----------" />
  <Dropdown
    style={{borderTopLeftRadius: 0, borderBottomLeftRadius: 0}}
    placeholder="---------Text----------"
    options={optionsFilterType}
    defaultSelectedKey="opt1" />
  <PrimaryButton text="查詢" />
</Stack>

Upon inspecting the final rendered elements using the Developer Tools in the browser, I observed that the mentioned style was applied to the <input> tag rather than its parent element (<div>). I am aware that applying the style to the parent <div> would remove the rounded corners, but I am unsure of how to implement the style correctly.

https://i.sstatic.net/XxlDN.png

Thank you for your assistance.

Answer №1

One effective suggestion from FluentUI is to utilize the styles property instead of style or className when modifying component styles:

<Stack horizontal={true}>
  <TextField
     styles={{
       fieldGroup: {
         borderRadius: 0,
         borderRight: '0px solid transparent',
       }
     }}
     placeholder="---------Text----------"
  />
  <Dropdown
    styles={{
      title: {
        borderRadius: 0,
      }
    }}
    placeholder="---------Text----------"
    options={optionsFilterType}
    defaultSelectedKey="opt1"
  />
  <PrimaryButton text="查詢" />
</Stack>

For a complete working example, check out this Codepen.

To learn more about Component styling, visit the link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a URL using Form Fields with Javascript or jQuery - Reg

Creating a Custom URL with Form Fields using JavaScript or jQuery I am looking to generate an external link by incorporating a form with a dynamic variable as shown below: (Where 2500 can be customized based on user input) The final URL will be display ...

Issue with JQuery Promise: fail() being invoked before promise resolution

In my TypeScript code, I encountered a peculiar issue with a jQuery promise. The fail() function is being executed immediately, logging an error message to the console, despite the promise resolving successfully afterwards. Here is the code snippet: ...

Troubles arise when utilizing getChannelData to configure socket.io in web audio,

I'm facing a problem where my connection gets disconnected as soon as I execute the code source.buffer.getChannelData(0).set(audio);. This issue occurs when I transcode an audio file and send the audio buffer to the client using socket.io for playback ...

What are some creative ways to design the selected tab?

In my Vue parent component, I have multiple child components. There are several elements that toggle between components by updating the current data. The issue is that I am unsure how to indicate which tab is currently active. I've tried various li ...

Display intricate state in ReactJS

I have designed a state with various types such as Checkbox, Slider, or Rating using Material-UI. I want to display these choices to the user. To better understand my implementation, I have created a sandbox: Sandbox. In line 261 of Form.js, I plan to out ...

Optimal placement and size for the slick slider

I am new to CSS and currently experimenting with the Slick slider on a project: My setup involves a div container that spans 100% of the width of the page. Inside this container, there is another div (housing the slider) that takes up 80% of the width. D ...

The result of calling addEventListener is undefined

My issue lies with the addEventListener function, as it is not working correctly. I've created a function that requires an event listener to track scrolling and then execute a callback function. window.addEventListener("scroll", checkPosition); Unf ...

Anticipate feedback from a new user

I'm currently working on a verification system that involves sending a message in one channel and triggering an embed with two emoji options (accept or deny) in another channel. The issue I'm facing is that the .awaitReaction function is getting ...

Is it necessary for me to explicitly establish onChange handlers in order to update state variables?

Imagine I have a form with numerous input controls that need to be tied to specific state variables. Is it necessary to manually create onChange=.. handlers for each one so that when I click Submit or press Enter, my state vars are updated? For example: c ...

Exploring React and Babel through VSCode debugging

I am currently working on a project that involves the following scripts: "dev": "babel-node --presets 'react,es2015' src/server.js" "start": "NODE_ENV=development babel-node --presets 'react,es2015' src/server.js" "build": "NODE_ENV=d ...

In order to extract a value from a different webpage, I must first make a request to that webpage and extract the XML value from it

I have been working on a project that requires displaying currency exchange rates. To achieve this, I initially tried using AngularJS to call another webpage for the exchange rate values, but I encountered issues as AngularJS can only make JSON/Rest URL ca ...

Using Grails to create remote functions with multiple parameters

Currently, I am able to send one parameter to the controller using the code snippet below in Javascript: <g:javascript> var sel = "test"; <g:remoteFunction action="newExisting" method="GET" update="updateThis" params="'sel='+s ...

Text parsing with jQuery

Hello fellow developers. I am interested in creating a text parser using jQuery. My goal is to develop a function that can take a string as input and convert it accordingly. Imagine we have a div with the following HTML structure: <div class="item"> ...

What is the best way to reach the assets/public directory from a routed page in Meteor?

I am currently developing a multipage application using Meteor and am facing an issue accessing public assets from a routed page. For instance, when I go to the route http://localhost:3000/editor, I would like to be able to utilize an image from public/im ...

Tips for identifying a pair of numbers (with varying ranges) in which one number must be present at all times

I am currently trying to understand the regex I have implemented in Angular 2 using Typescript: /[0-5]?[0-9]?/ Surprisingly, this regular expression works flawlessly to match any valid minute from 1 to 59, even though it seems like an empty string would ...

Aligning images in a table grid of 300px by 300px dimensions

I've included my code below and I am searching for the most effective method to use CSS to center an image both horizontally and vertically within a 300 by 300 pixel square. If the image is larger, it should be resized to fit within the square, while ...

Bootstrap form toggle switch component for ReactJS

I'm having trouble figuring out why the default value for my react-bootstrap switch won't set to false (off). It seems like the only way it changes is when I trigger the onChange event handler. Am I overlooking something? Below is the section of ...

Guide for creating a test case for the componentWillReceiveProps method in my React code

Here is the code snippet I need help with: componentWillReceiveProps(nextProps) { this.checkCommentChange(nextProps); if (nextProps.isOpen !== this.state.isOpen) { this.setState({ disableCancel: nextProps.commen ...

Is there a method to incorporate a click event for the confirm button in the ElMessageBox UI element?

When I try to remove data from the table, I need a warning message to appear in the center of the screen first. The delete function is already set up, but I'm struggling to figure out how to implement a confirm button click event with ElMessageBox. I ...

Pair a specific portion of text with another string

I'm having trouble finding a substring within a string. The substring and the string are as follows: var str="My name is foo.I have bag(s)" var substr="I have bag(s)" When I use str.match(substr), it returns null, probably because the match() funct ...